------解决方案-------------------- select ID,classID,a_isPass,b_isPass,c_isPass from A where (classID=1 and a_isPass=1) or (classID= 2 and b_isPass=1) or (classID=3 and c_isPass=1)
lz对于case when 不熟悉吗? case when 也比较简单 ------解决方案--------------------
select ID,classID,a_isPass,b_isPass,c_isPass from A where classID in(1,2,3) and a_isPass=1
------解决方案-------------------- case when then 只能用操作classid的字段呀,不能从这个字段到另一个字段吧。。。 ------解决方案-------------------- 感觉不是查询是修改 ------解决方案-------------------- update a
set a_isPass =
(case when classid = 1 then 1 else 0 end),
b_isPass =
(case when classid = 2 then 1 else 0 end),
c_isPass =
(case when classid = 3 then 1 else 0 end) ------解决方案-------------------- 樓主是要這個麼
SELECT
ID,
CLASSID,
(CASE CLASSID=1 THEN 1 ELSE A_ISPASS END) AS A_ISPASS,
(CASE CLASSID=2 THEN 1 ELSE B_ISPASS END) AS B_ISPASS,
(CASE CLASSID=3 THEN 1 ELSE C_ISPASS END) AS C_ISPASS
insert into #tb
select 1,1,1,0,0
union all
select 2,2,0,1,0
union all
select 3,3,0,1,1
union all
select 4,2,1,1,0
*/
--解法1
select tID,classID,'pass'=case when classid=1 and a_ispass=1 then 'a_ispass'
when classid=2 and b_ispass=1 then 'b_ispass'
when classid=3 and c_ispass=1 then 'c_ispass'else '' end
from #tb
--解法2