sql可以用select根据不同条件查询同一个字段2次吗? sql select语句
更新时间:2022-03-08 10:38:01 • 作者:KURT •阅读 4314
这个sql语句怎么写:按照两个条件查询
select top 10 case when A > 0 then A when B >0 then B else 0 end ab,
TID from Test where (a>0 or b>0) and TID="&cid&"
sql语句怎么样一次性查询多个条件,并分列显示?
方法一,分别查询出来,结果再关联
select fnum1,fnum2 from
(select count(*) as fnum1 from 表名 where a=2 and b=3) t1,
(select count(*) as fnum2 from 表名 where a=3 and b=5) t2方法二
select sum(case when a = 2 and b = 3 then 1 else 0 end) as fnum1,
sum(case when a = 3 and b = 5 then 1 else 0 end) as fnum2
from 表名
where a = 2 and b = 3
or a = 3 and b = 5有问题请追问