19960715lww

case函数的妙用select person,ticket_name,sum(case  when  ticket_name is not null then 1 end) as 总票数  

,sum(case  when  ticket_price is not null then ticket_price end) as 总金额  from ticket_table group by person,ticket_name  

是从网上粘贴的,数据就不附上了

将表的数据根据person ticket_name 分组  每个person ticket_name 分到的数据在遍历

case  when  ticket_name is not null then 1 end  当数据ticket_name is not null 的时候ticket返回的是1,sum就加一;

当后面有where 语句的时候先执行where条件

where -----group by ---- select --------case

 

仅是自己现阶段的理解

原例http://blog.csdn.net/u011244173/article/details/46118367

分类:

技术点:

相关文章:

  • 2021-10-01
  • 2021-10-12
  • 2019-07-29
  • 2019-03-16
  • 2021-12-01
  • 2021-12-03
  • 2020-05-18
猜你喜欢
  • 2020-05-15
  • 2021-08-07
  • 2021-09-19
  • 2021-08-04
  • 2021-06-01
  • 2021-12-19
  • 2021-08-21
相关资源
相似解决方案