我有一张类似于以下内容的表格:
+----+------+----------+
| id | Order| SalesMan |
+----+------+----------+
| 1 | 1001 | 1 |
| 2 | 1001 | 2 |
| 3 | 1002 | 1 |
| 4 | 1002 | 4 |
| 5 | 1003 | 2 |
+----+------+----------+
我想选择与AND运算符共享多个Sales Men的订单。就像只显示由Salesmen 1&amp ;; 2。
答案 0 :(得分:3)
根据我对您的问题的理解,将会有一个订单与多个销售人员相关联。如果您只需要了解那些与销售员1和2相关的订单,那么您可以这样做:
SELECT `order`
FROM tbl
WHERE salesMan=1
AND `order`
IN (select `order` from tbl where salesMan=2)
这是SQL Fiddle以便更好地理解..
编辑:我已根据您的需要更改了查询a / c:
SELECT orders
FROM tbl
WHERE salesMan
IN (1,2,3)
GROUP BY orders
HAVING count(orders)>1;
检查fiddle demo此处
答案 1 :(得分:0)
使用GROUP BY
和HAVING
条款。
SELECT salesMan
FROM tbl
GROUP BY salesMan
HAVING COUNT(salesMan) > 1;
答案 2 :(得分:0)
试试这个
SELECT * FROM table WHERE SalesMan IN(1,2);