【发布时间】:2019-10-31 18:34:40
【问题描述】:
我试图根据特定列的值(在我的情况下为jjsc_rev_cycle)以不同的方式提取字段值的计数(作为两个不同的值)。
如果jjsc_rev_cycle 是0
然后得到
count(distinct jjsc_job_no) as new_order_count
否则
count(distinct jjsc_job_no) as rev_order_count
我正在尝试在这样的 1 个查询中执行此操作,但显示语法错误:
SELECT jjsc_rev_cycle,
CASE jjsc_rev_cycle
WHEN jjsc_rev_cycle = 0
THEN select count(distinct jjsc_job_no) as new_order_count
ELSE select count(distinct jjsc_job_no) as rev_order_count
END
FROM jdwf_job_status_cycle
WHERE jjsc_time >= '2017-06-01' and jjsc_time <= '2017-06-03' group
by jjsc_wf_userid
示例表数据:
jjsc_job_no jjsc_rev_cycle jjsc_time
7201170 0 2019-06-12 15:49:26
7201171 0 2019-06-12 15:35:56
7201172 0 2019-06-12 15:31:49
7201162 0 2019-06-12 15:31:15
7201166 1 2019-06-12 15:30:39
7201169 0 2019-06-12 15:29:22
7201164 0 2019-06-12 15:28:38
7201168 0 2019-06-12 15:27:55
7201167 0 2019-06-12 15:26:49
7201165 0 2019-06-12 15:25:51
7201161 0 2019-06-12 15:24:28
7201160 0 2019-06-12 15:22:21
7201159 0 2019-06-12 15:21:13
7201158 0 2019-06-12 15:20:16
7200991 0 2019-06-11 16:18:15
7200999 0 2019-06-11 14:38:48
7200991 1 2019-06-11 14:37:56
7200984 0 2019-06-11 14:37:06
7201097 0 2019-05-30 12:55:43
预期输出:
new_order_count rev_order_count
17 2
我做错了什么?或者有其他方法可以代替吗?
【问题讨论】: