llgd.net
当前位置:首页 >> 怎么才能将CAsE whEn放入whErE中 >>

怎么才能将CAsE whEn放入whErE中

不能放在where里边,像你这样的,用子查询去查会比较容易select * from where 字段 in(select case when 字段>1 then 1 else 0 end from 表)

你应该这样写 select * from 表 where 1=1 and (case when a=1 then a when 表.字段='asdfasdf' then b end)='值

SELECT "LOG".localtime, ( CASE WHEN "LOG".objecttype=0 THEN (SELECT content FORM "LOG" log1 WHERE "LOG".id=log1.id ) ---维护值才行 WHEN "LOG".objecttype=1 THEN (SELECT name FORM "GROUP" group1 WHERE "LOG".object=group1.id ) WHE...

1> 2> SELECT * FROM t_test_sub; 3> GO id main_id value ----------- ----------- ---------- 2 12 TWOTWO 11 21 AAAA 12 22 BBBB 13 NULL CCCC 14 NULL DDDD 15 NULL EEEE (6 行受影响) 1> UPDATE t_test_sub set value = 'test' WHERE case ...

SELECT (CASE WHEN MASTERJOB = '' THEN JOBNO ELSE MASTERJOB END)WO,JOBNO,CHILDJOB,CODE,BDESC,P_CODE, (SELECT TOP 1 BDESC FROM PRO WHERE CODE=RESVT.P_CODE)CBDESC,QTY,UNIT,LOC, (CASE WHEN exists(SELECT top 1 TAXUP FROM ANT B LEFT ...

select id,age,case id when '1' then 'aaa' when '2' then 'bbb' else NULL end from test; 这是一个使用case when then的句子,其中id是一个字段,test是表明 其实where后用也行,例句 SELECT * FROM CUSTOMERS WHERE DEPT_CODE = (CASE @ZTYP...

select * from 表 where 1=1 and (case when a=1 then a when 表.字段='asdfasdf' then b end)='值 ase when 变量a='provider' then 'cp.id' else {1} end 这就不是判断语句,这是赋值语句,where不能在后面 SQL code ? 1 2 3 4 SELECT CK.RESPE...

可以 的 where 字段值 = case when ...

Case When 只能简单的返回一个值,不能让你拼SQL条件

简单的用法比如: selelct user_id, user_name from tb_users where user_id in (select user_id from tb_course) 这个查询是查询在tb_course表中存在的user记录。 使用exists,写成 select user_id, user_name from tb_users where exists (sel...

网站首页 | 网站地图
All rights reserved Powered by www.llgd.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com