为了简化我有一个表,我只是想用蓝色数据进行选择,对我来说很棘手,因为我必须使用arg
,但我只会得到记录5,7,10, 12但我希望得到6,8,9到
我该怎么做?
答案 0 :(得分:0)
你似乎想要:
select t.*
from t
where t.tansdocnumber in (select t2.transdocnumber from t t2 where t2.textanswer = 'Dimobili D2);
答案 1 :(得分:0)
选择包含所需文本列的行,并匹配相应的ID以获取所需的输出。
declare @table table (transdocnumber int, textanswer varchar(20))
insert @table (transdocnumber,textanswer)
select 4631, 'Dimibilli D4' union all
select 4631, '' union all
select 5055, 'Dimibilli D2' union all
select 5055, '' union all
select 5270, 'Dimibilli D2' union all
select 5270, '' union all
select 5270, '' union all
select 5513, 'Dimibilli D2' union all
select 6279, 'Dimibilli D4' union all
select 6616, 'Dimibilli D2' union all
select 6773, 'Dimibilli D4'
select t.transdocnumber,t.textanswer from (
select transdocnumber from @table where textanswer = 'Dimibilli D2' ) x
inner join @table t on x.transdocnumber = t.transdocnumber where t.textanswer = ''
union all
select transdocnumber,textanswer from @table where textanswer = 'Dimibilli D2'
order by transdocnumber
解决方案:
SELECT t.transdocnumber, t.extrafield_id, t.textanswer, t.BooleanAnswer, t.DtAlt
FROM (
SELECT *
FROM TABLE
WHERE textanswer = 'Dimibilli D2'
) x
INNER JOIN TABLE t ON x.transdocnumber = t.transdocnumber
WHERE t.textanswer = ''
UNION ALL
SELECT transdocnumber, extrafield_id, textanswer, BooleanAnswer, DtAlt
FROM TABLE
WHERE textanswer = 'Dimibilli D2'
ORDER BY transdocnumber
答案 2 :(得分:0)
select * from table
where textanswer not in ('dimobilli d4')
答案 3 :(得分:0)
根据我的理解,你想要使用textanswer ='dimibilli d2'和textanswer ='dimibilli d2'而不是第4行来获取行。
你不能这样做,你应该以某种方式区分你想要的行。
使用
select * from table
where (textanswer='dimibilli d2' or textanswer = '')
select * from table
where (textanswer='dimibilli d2' or textanswer = '') and TransDocNumber>5000;
这应该有效
答案 4 :(得分:0)
尝试使用以下查询:
select * from table
where (TextAnswer='Dimobili D2' or BooleanAnswer = '1') and TextAnswer!=''