Sql 查询集锦

1、在这个表里 统计出第二张图的数据,写出Sql语句

select  date ,stockCode,
SUM(case buysell when  'B' then Quantity else 0 end)as buyQuantity,
SUM(case buysell when  'S' then Quantity else 0 end) as SellQuantity
from table_1
group by stockCode,date

Case when 与 sum() count(*)搭配使用,统计经常用到

猜你喜欢

转载自www.cnblogs.com/jksun/p/9224094.html