我的情况如下。我有一个表订单(OrderId,ItemId),我希望获得所有订单,其中ItemId 1和2即将来到simulataneoudsly
OrderId ItemId
1000 1
1001 2
1002 1
1002 2
1002 3
1003 1
1003 2
1004 4
1004 5
1005 3
1006 1
1006 3
根据上面的表数据和问题......我应该得到输出OrderId 1002和1003.
答案 0 :(得分:3)
使用 import tkinter as tk
class Example(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
self.labelLists = []
self.labelBLists = []
self.Label1 = tk.Label(self,text=str(1),bg="red")
self.Label1.pack()
self.Label1.bind("<Enter>", self.on_enter1)
self.Label1.bind("<Leave>", self.on_leave1)
self.Labela = tk.Label(self,text="",bg="blue")
self.Labela.pack()
self.Label2 = tk.Label(self,text=str(2),bg="red")
self.Label2.pack()
self.Label2.bind("<Enter>", self.on_enter2)
self.Label2.bind("<Leave>", self.on_leave2)
self.Labelb = tk.Label(self,text="",bg="blue")
self.Labelb.pack()
self.Label3 = tk.Label(self,text=str(3),bg="red")
self.Label3.pack()
self.Label3.bind("<Enter>", self.on_enter3)
self.Label3.bind("<Leave>", self.on_leave3)
self.Labelc = tk.Label(self,text="",bg="blue")
self.Labelc.pack()
def on_enter1(self, event):
self.Labela.config(text=self.Label1.cget("text"))
def on_leave1(self, enter):
self.Labela.config(text="")
def on_enter2(self, event):
self.Labelb.config(text=self.Label2.cget("text"))
def on_leave2(self, enter):
self.Labelb.config(text="")
def on_enter3(self, event):
self.Labelc.config(text=self.Label3.cget("text"))
def on_leave3(self, enter):
self.Labelc.config(text="")
if __name__ == "__main__":
root = tk.Tk()
Example(root).pack(side="top", fill="both", expand="true")
root.mainloop()
和COUNT
:
HAVING
如果SELECT OrderId
FROM Orders
WHERE
ItemId IN(1, 2)
GROUP BY OrderId
HAVING COUNT(ItemId) = 2
中允许重复ItemId
,请使用:
OrderId
答案 1 :(得分:0)
使用嵌套查询的另一个选项是:
SELECT orderId
FROM ORDERS o
WHERE o.itemId = 1
AND EXISTS (SELECT 'X'
FROM ORDERS o1
WHERE o1.orderId = o.orderId
AND o1.itemId = 2);