如下两条常用sql,统计分类数据,你能说出区别吗?
一、常用sql一:select
r.cid,
r.depart_id,
r.employ_id,
r.create_by,
count(DISTINCT r.form_type) as dailyReportNum
FROM
report r
where
1=1
GROUP BY
r.employ_id
二、常用sql二:
select
r.cid,
r.depart_id,
r.employ_id,
r.create_by,
sum(case WHEN df.form_type=1 then 1 else 0 end ) as dailyReportNum
FROM
report r
where
1=1
GROUP BY
r.employ_id