select
count(distinct pmsinfo.id,pmsinfo.categoryid = 127 or null) msaj,
-- count(distinct pmsinfo.id,pmsinfo.categoryid = 128 or null) xsaj,
count(distinct pmsinfo.id,pmsinfo.causeofactionid in (2,3,4,5,6,7,8,9,10,11,12,13,14) or null) whgj_cause,
count(distinct casecustomer.id,casecustomer.identitycategoryid = 46 and customerfeature.featureid = 99 or null) wcnr_id,
-- count(distinct casecustomer.id,casecustomer.identitycategoryid = 46 and customerfeature.featureid = 100 or null) cjr_id,
-- count(distinct casecustomer.id,casecustomer.identitycategoryid = 43 or null) gsqy_id,
-- count(distinct casecustomer.id,casecustomer.identitycategoryid = 44 or null) jgdw_id,
(case when pmsinfo.categoryid = 135 then consultsum.amount else casesum.amount end) amount,
officebase.officename
from
pms_info pmsinfo
left join office_base officebase on pmsinfo.tenantid = officebase.id
left join fms_case_summary casesum on pmsinfo.id = casesum.infoid
left join fms_consult_summary consultsum on pmsinfo.id = consultsum.infoid
left join crm_case_customer casecustomer on pmsinfo.id = casecustomer.infoid
left join crm_case_customer_feature customerfeature on casecustomer.id = customerfeature.customerid
where pmsinfo.isdeleted = false and pmsinfo.tenantid = 5 and pmsinfo.typeid = 0
and pmsinfo.statusid in (1,2,3,4,5,6,7,12,13)
group by statistictime
結果:
(case when pmsinfo.categoryid = 135 then consultsum.amount else casesum.amount end) amount,
(case when pmsinfo.categoryid = 135 then date_format(consultsum.createtime,'%y%m%d') else date_format(casesum.createtime,'%y%m%d') end) statistictime
如果categoryid 等於135,取consultsum表的amount 和 consultsum表的createtime。
如果不等於,取casesum表的amount 和 casesum表的createtime。並取別名
date_format(consultsum.createtime,'%y%m%d') :將日期格式化,例:(2019-01-10 00:00:00)—>20190110
count(pmsinfo.categoryid = 127 or null) msaj, == 127時統計,注意加or null 不加不管用
count(pmsinfo.causeofactionid in (2,3,4,5,6,7,8,9,10,11,12,13,14) or null) whgj_cause, 等於後邊括號內任意乙個時統計,注意加or null 不加不管用
count(casecustomer.identitycategoryid = 46 and customerfeature.featureid = 99 or null) wcnr_id, = 46 且 customerfeature.featureid = 99 時統計,注意加or null 不加不管用
count(distinct casecustomer.id,casecustomer.identitycategoryid = 46 and customerfeature.featureid = 99 or null) wcnr_id,
//根據casecustomer.id去重,並且當casecustomer.identitycategoryid = 46 和customerfeature.featureid = 99時統計
sql 條件判斷
case具有兩種格式。分支結構case語句和條件判斷case語句。分支結構case語句,類似於switch select case user name when 張三 then zhangsan when 李四 then lisi when 王五1 then wangwu else 找不到對應 en...
sql條件語句
transact sql 語言使用的流程控制命令與常見的程式語言類似主要有以下幾種控制命令。4.6.1 if else 其語法如下 if 條件表示式 命令列或程式塊 else 條件表示式 命令列或程式塊 其中 條件表示式 可以是各種表示式的組合,但表示式的值必須是邏輯值 真 或 假 else子句是可...
SQL 條件查詢
按條件表示式 其中 意思一樣,都是不等於,建議用 邏輯表示式 and or not 模糊查詢 like between and in is null 檢視name第3個字元為n,第五個為z的記錄 select from user where name like n z between and 可以提...