Sql 判断
来源:百度知道 编辑:UC知道 时间:2024/07/07 21:03:02
如何书写类似判断sql
某表数据有类型、有值、primary三列
如何检索两列:
列1:当类型等于1,如没有01显示primary=true值
列2:当类型等于2,如没有02显示primary=true值
要求输出为1条数据
不懂啊,麻烦给个实例好么?
某表数据有类型、有值、primary三列
如何检索两列:
列1:当类型等于1,如没有01显示primary=true值
列2:当类型等于2,如没有02显示primary=true值
要求输出为1条数据
不懂啊,麻烦给个实例好么?
select primary=(case when
(select count(*) from tb where type = '1' and value='01')=0 then 'true'
when (select count(*) from tb where type='2' and value='02')=0 then 'true'
else 'false' end
) from 表
if
else
不懂问我
hi wo ,我给你例子
问题问的有点不太清楚。
select
case (select isnull(count(1),0) from 表名 where 类型='1' and 值='01') when 0 then 'primary=true' else '' end as 列1,
case (select isnull(count(1),0) from 表名 where 类型='2' and 值='02') when 0 then 'primary=true' else '' end as 列2
也不知道是不是你想要的,如果不是,再补充说明一下吧。
case 类型
when 1 then
decode("值",01,值,decode("primary",true,primary,null))
when 2then
decode("值",02,值,decode("primary",true,primary,null))
不知对不!
select
case when 类型=1 and 有01 then 显示的值 else null en