Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 同一查询中的不同条件_Sql_Sql Server - Fatal编程技术网

Sql 同一查询中的不同条件

Sql 同一查询中的不同条件,sql,sql-server,Sql,Sql Server,在这两种情况下,我有两种不同的情况 条件类似于子状态在('lead','opp')中的位置 对于无效-其中子状态为('complete'、'inprogress'、'open') 如何在同一个查询中实现这两个条件???只需这样做 select sum(case when status='qualififed' then 1 else 0 end ) as touched, sum(case status='Disqualififed' then 1 else 0 end ) as invalid

在这两种情况下,我有两种不同的情况

条件类似于子状态在('lead','opp')中的位置 对于无效-其中子状态为('complete'、'inprogress'、'open')

如何在同一个查询中实现这两个条件???

只需这样做

select sum(case when status='qualififed' then 1 else 0 end ) as touched,
sum(case status='Disqualififed' then 1 else 0 end ) as invalid
from lead
就这么做吧

select sum(case when status='qualififed' then 1 else 0 end ) as touched,
sum(case status='Disqualififed' then 1 else 0 end ) as invalid
from lead

只是加上你的条件<代码>条件1和/或条件2和/或条件3时的情况,然后X else Y end仅添加您的条件<代码>条件1和/或条件2和/或条件3然后X else Y end时的情况