简单三个表之间关联 与 case when语句的应用
2024-08-26 10:32:48
case when语句运用
select b.cur_branch,
count(p.conttract_id),
sum(case when p.aff_date is null then p.payable_money else 0 end),
sum(case when p.aff_date is null and p.fee_item ='租金' then p.payable_money else 0 end),
sum(case when p.aff_date is null and p.fee_item ='电费' then p.payable_money else 0 end),
sum(case when p.aff_date is not null then 1 else 0 end),
sum(case when p.aff_date is null then 1 else 0 end)
from WG_PJHSB p, wg_jzmb b
where p.station_id = b.station_code
group by b.cur_branch
order by b.cur_branch
运用1:sum(case when p.aff_date is null then p.payable_money else 0 end)
累加票据金额
运用2:sum(case when 条件语句l then 1 else 0 end)
累加计数使用。
最新文章
- 验证xml是否有效于.dtd文件
- 保存会话数据——cookie学习
- OC中的消息传递和初始化
- mysql 查询随机条记录的sql语句和php计算概率
- 工作案件1 一切都是有check引起的
- Java之String,StringBuffer,StringBuilder类
- POJ_3321_APPLE_TREE
- ACM YTU 十进制与八进制的转换 (栈和队列) STL栈调用
- android进程间通信:使用AIDL
- Ubuntu环境下mysql常见的操作
- JAVA(四)类集/枚举
- VLC框架分析
- 【巷子】---flux---【react】
- Innodb引擎状态查看
- Django_rest_framework_基础
- MAC VNC SSH roo用户开通
- div 移动
- 关于sleep的理解
- C语言ctype.h字符函数和字符串
- consider increasing the maximum size of the cache.