当前位置: 首页 > news >正文

中国机械加工网站建立网站一般包括什么等方式

中国机械加工网站,建立网站一般包括什么等方式,腾和企业网站管理系统,做导购网站要多少钱大家好,我是空空star,本篇带大家了解一道简单的力扣sql练习题。 文章目录前言一、题目:1084. 销售分析III二、解题1.正确示范①提交SQL运行结果2.正确示范②提交SQL运行结果3.正确示范③提交SQL运行结果4.正确示范④提交SQL运行结果5.其他总结…

大家好,我是空空star,本篇带大家了解一道简单的力扣sql练习题。

文章目录

  • 前言
  • 一、题目:1084. 销售分析III
  • 二、解题
    • 1.正确示范①
      • 提交SQL
      • 运行结果
    • 2.正确示范②
      • 提交SQL
      • 运行结果
    • 3.正确示范③
      • 提交SQL
      • 运行结果
    • 4.正确示范④
      • 提交SQL
      • 运行结果
    • 5.其他
  • 总结


前言


一、题目:1084. 销售分析III

Table: Product

+--------------+---------+
| Column Name  | Type    |
+--------------+---------+
| product_id   | int     |
| product_name | varchar |
| unit_price   | int     |
+--------------+---------+
Product_id是该表的主键。
该表的每一行显示每个产品的名称和价格。

Table: Sales

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| seller_id   | int     |
| product_id  | int     |
| buyer_id    | int     |
| sale_date   | date    |
| quantity    | int     |
| price       | int     |
+------ ------+---------+
这个表没有主键,它可以有重复的行。
product_id 是 Product 表的外键。
该表的每一行包含关于一个销售的一些信息。

编写一个SQL查询,报告2019年春季才售出的产品。即仅在2019-01-01至2019-03-31(含)之间出售的商品。

以 任意顺序 返回结果表。

查询结果格式如下所示。

输入:
Product table:
+------------+--------------+------------+
| product_id | product_name | unit_price |
+------------+--------------+------------+
| 1          | S8           | 1000       |
| 2          | G4           | 800        |
| 3          | iPhone       | 1400       |
+------------+--------------+------------+
Sales table:
+-----------+------------+----------+------------+----------+-------+
| seller_id | product_id | buyer_id | sale_date  | quantity | price |
+-----------+------------+----------+------------+----------+-------+
| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |
| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |
| 2         | 2          | 3        | 2019-06-02 | 1        | 800   |
| 3         | 3          | 4        | 2019-05-13 | 2        | 2800  |
+-----------+------------+----------+------------+----------+-------+
输出:
+-------------+--------------+
| product_id  | product_name |
+-------------+--------------+
| 1           | S8           |
+-------------+--------------+

解释:
id为1的产品仅在2019年春季销售。
id为2的产品在2019年春季销售,但也在2019年春季之后销售。
id 3的产品在2019年春季之后销售。
我们只退回产品1,因为它是2019年春季才销售的产品。

二、解题

1.正确示范①

提交SQL

select product_id,product_name from Product 
where product_id in(select product_id from Saleswhere sale_date between '2019-01-01' and '2019-03-31'
)
and product_id not in (select product_id from Saleswhere substr(sale_date,1,7)>='2019-04'or substr(sale_date,1,7)<'2019-01'
);

运行结果

2.正确示范②

提交SQL

select distinct u1.product_id,u1.product_name 
from Product u1 
left join Sales u2 
on u1.product_id=u2.product_id 
and u2.sale_date between '2019-01-01' and '2019-03-31'
left join Sales u3
on u1.product_id=u3.product_id 
and (substr(u3.sale_date,1,7)>='2019-04'
or substr(u3.sale_date,1,7)<'2019-01')
where u2.product_id is not null 
and u3.product_id is null;

运行结果

3.正确示范③

提交SQL

select   u1.product_id,u1.product_name 
from Product u1 
left join Sales u2 
on u1.product_id=u2.product_id 
and u2.sale_date between '2019-01-01' and '2019-03-31'
left join Sales u3
on u1.product_id=u3.product_id 
and (substr(u3.sale_date,1,7)>='2019-04'
or substr(u3.sale_date,1,7)<'2019-01')
group by u1.product_id,u1.product_name 
having count(u2.product_id)>0 and count(u3.product_id)=0;

运行结果

4.正确示范④

提交SQL

select   u1.product_id,u1.product_name 
from Product u1 
left join Sales u2 
on u1.product_id=u2.product_id 
group by u1.product_id,u1.product_name 
having min(u2.sale_date)>='2019-01-01' 
and max(u2.sale_date)<='2019-03-31';

运行结果

5.其他


总结

正确示范①思路:
限定product_id in 2019年春季销售过 and product_id not in 2019年春季之外销售过的product_id;
正确示范②思路:
innot in 转换为 left join 的形式,
在最后限定u2.product_id is not null and u3.product_id is null,在获取结果时加上 distinct 去重;
正确示范③思路:
innot in 转换为 left join 的形式,
group by u1.product_id,u1.product_name 分组并去重,再通过
having count(u2.product_id)>0 and count(u3.product_id)=0筛选;
正确示范④思路:
group by u1.product_id,u1.product_name 分组并去重,通过having min(u2.sale_date)>=‘2019-01-01’
and max(u2.sale_date)<=‘2019-03-31’ 筛选;

http://www.yayakq.cn/news/683306/

相关文章:

  • 网站开发的源代码怎么算侵权什么企业做网站
  • 做游戏推广网站动漫制作专业介绍及就业方向
  • angular做的网站大全微信公众平台小程序管理在哪里
  • 网站一般要设计几页做网站需要考虑seo吗
  • 网站建设的500字小结深圳住房和建设局网站首页
  • 海参企业网站怎么做html做音乐网站模板
  • 自己免费建设网站厦门建网站
  • 大连市开发区网站建设公司厦门seo推广公司
  • 做网站公司昆明如何做一份营销策划方案
  • 中山市规划建设局网站专业建设典型案例
  • 天长哪个广告公司做网站软文素材
  • 怎么做镜像网站莱芜信誉好的网络推广公司
  • 做农产品网站需要做的准备网站设计论文提纲
  • 怎么才能建立一个网站卖东西内蒙古建设住房与城乡厅官方网站
  • 免费企业网站cms系统好看的个人网站模板
  • 太原做网站 小程序wordpress主题开发视频教程
  • 建设一个网站的意义西昌手机网站建设成都彩钢顶防水
  • 翻书效果的网站中国建设银行湖南分行官网站
  • 创新模式_提高质量_建设一流的数学人才培养基地 教学成果奖申报网站在网站上使用特殊字体
  • 外贸公司网站模板电子商务主要是干嘛的
  • 江苏省建设厅工会网站网站色彩代码
  • wordpress网站接入qq企业网站功能报价
  • 做网站在哪个地方买空间wordpress登录
  • 深圳网站制作公司资讯接外贸单的平台
  • 阳江招聘网站哪里最好找工作海珠一站式网站建设
  • 山东商祺网站建设优化广东大唐建设网站
  • 房产网站开发手工制作房子硬纸板
  • 网站制作公司加盟百度小程序注册流程
  • asp网站应用程序在线视频制作
  • 做最好言情网站松滋住房和城乡建设局网站