我的数据库中有此表:
id name source
------------------------------
1 John Doe fbs
2 Clara Wayne fbs
3 John Doe dem
4 Markus Clark lp
5 Markus Clark fbs
6 John Doe sms
我需要提取这样的内容,其中列source
既不是dem
也不是sms
:
id name source
------------------------------
2 Clara Wayne fbs
4 Markus Clark lp
答案 0 :(得分:1)
我假设未选择John Doe
,因为他的记录之一属于sms
来源,您不想在结果中包括该信息。
SELECT *
FROM YOUR_TABLE
WHERE name NOT IN (
SELECT name
FROM YOUR_TABLE
WHERE source IN ('dem','sms')
);
答案 1 :(得分:0)
您可以选择喜欢的数据。...
SELECT * FROM YOUR_TABLE_NAME WHERE SOURCE NOT IN ('DEM', 'SMS')
或者您可以这样做...
SELECT DISTINCT SOURCE, NAME, ID FROM TABLE_NAME T WHERE T.NAME NOT IN (SELECT TOP 1 NAME FROM TABLE_NAME WHERE SOURCE IN('DEM', 'SMS'))
答案 2 :(得分:0)
select * from your_table where source != 'dem' and source != 'sms'
另一种解决方法
答案 3 :(得分:0)
您可以像这样列出“不想要的值”:
SELECT * FROM yourtable WHERE source NOT IN ('fbs','lp');
答案 4 :(得分:0)
您可以使用:
CANEraseResponse.data[8] = {0x00, 0xFF, 0x00, 0x04, 0x02, 0x00, 0x00, 0x00};
答案 5 :(得分:0)
尝试一下
SELECT *
FROM yourtable t
WHERE NOT EXISTS (
SELECT 1
FROM yourtable
WHERE id = t.id
AND name = t.name
AND source IN ('dem', 'sms')
)