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(*)搭配使用,统计经常用到

 

posted on 2018-06-25 14:16  heihaha  阅读(92)  评论(0编辑  收藏  举报