因爲你不希望獲取訂單ID 5,6,所以你可以通過下面的query
SELECT *
FROM Orders
WHERE OrderID NOT IN(5,6);
更新按用戶要求排除這些命令:
SELECT a.myid as OrderId FROM
(
SELECT a.m*10000+b.n*1000+c.p*100+d.q*10+e.r AS myid FROM
(SELECT 0 m UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) a
JOIN
(SELECT 0 n UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) b
JOIN
(SELECT 0 p UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) c
JOIN
(SELECT 0 q UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) d
JOIN
(SELECT 0 r UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) e
ORDER BY myid
) a
LEFT JOIN orders b ON a.myid=b.orderid
WHERE a.myid IN (1,2,3,11,12,6) AND b.orderid IS NULL;
只需將您的訂單列表放在a.myid()中並執行上面的查詢即可。
進一步如果您自己的訂單更多,我們可以相應地修改查詢。
我有點困惑,你想要什麼結果? –
我有一定數量的訂單ID(說有人給了我一些隨機的訂單ID,他/她想讓我添加訂單ID,這在表中並不存在)。現在我只想知道匹配訂單ID不在數據庫中。合理? – user3209114
@ user3209114 ...是否「說某人給了我一些隨機的訂單ID,並且他/她想要我添加表中不存在的訂單ID」,這意味着您想要比較訂單表的'OrderId'和另一個表數據。我正確嗎? – Mathew