20220709练习内容
1.对InternationalSales进行条件查询。
条件如下:
1.销售日期在2019年10月1日至2019年10月7日;
2.国家为USA;
3.按销售日期进行降序排列。
select * from [Sales].[dbo].[InternationalSales]
where[Country]='USA'
AND Date between '2019-10-1' and '2019-10-7'
order by [Date] desc
2.对geo表进行查询,筛选出城市名称中同时包含字母"a"和字母"b"的所有数据。
select * from [dbo].[geo]
where [City] like '%a%'
and [City] like '%b%'
3.对product表进行条件筛选,同时与InternationalSales关联查询。
条件如下:
1.产品品类为All Season。
2.需要显示每种产品的收入。
select InternationalSales.ProductID,
sum([Revenue]) 销量
from product a
left join InternationalSales b
on a.ProductID=b.ProductID
WHERE [Product] LIKE'%All Season'
GROUP BY b.ProductID
4.关联查询product表和InternationalSales表,Category为'Urban'的产品的平均收入。
select Category,avg([Revenue]) 平均收入
from product a
left join InternationalSales b
on a.ProductID=b.ProductID
where Category='Urban'
group by Category
5.对InternationalSales进行分组计算。
条件如下:
1.按日期和国家进行分组;
2.计算分组后的收入总和;
3.需要显示的数据有date,country和收入总和,总和列重命名为"收入总和";
4.筛选"收入总和"大于1000000;
5.销售日期在'2012-6-15'至'2012-7-15'之间;
6.按销售日期进行正序排列。
select date,[Country],sum([Revenue]) 收入总和
from [dbo].[InternationalSales]
group by date,[Country]
having sum([Revenue])>1000000
and date between '2012-6-15' and '2012-7-15 '
order by Date
已学内容回顾