CREATE TABLE CUSTOMER (
CUSID VARCHAR(25) NOT NULL,
CNAME VARCHAR(50),
CONSTRAINT CUSTOMER_PKEY PRIMARY KEY (CUSID),
);
CREATE TABLE SHOP (
SHOPID VARCHAR(10) NOT NULL,
ADDRESS VARCHAR(25),
CONSTRAINT SHOP_PKEY PRIMARY KEY (SHOPID),
);
CREATE TABLE VISIT (
CUSID VARCHAR(25) NOT NULL,
SHOPID VARCHAR(10) NOT NULL,
VDATE DATE NOT NULL,
CONSTRAINT VISIT_PKEY PRIMARY KEY (CUSID, SHOPID, VDATE),
CONSTRAINT VISIT_FKEY1 FOREIGN KEY (CUSID) REFERENCES CUSTOMER(CUSID),
CONSTRAINT VISIT_FKEY2 FOREIGN KEY (SHOPID) REFERENCES SHOP(SHOPID)
);
如何找到已被訪問過至少兩次由名爲'john'的客戶訪問的商店的地址? (CUSID> 2)的CNAME ='約翰'GROUP BY CUSID的SELECT CUSID(CUSID FROM CUSTOMER WHERE CNAME ='john'GROUP BY CUSID HAVING COUNT(CUSID)> 2);選擇地址從商店天然加入訪問。具有計數條件和等條件的Oracle Sql 3表
我已經嘗試了很多種連接,似乎在我把count和equal條件放在一起之後,我的結果將會是0行。
提示連接表和用戶的WHERE子句限制 – Randy 2013-05-06 12:22:41
的SO的目的是建立答案的存儲庫中的行*編程*這將是感興趣的其他人的問題。這不是代理服務的功課。 – APC 2013-05-06 12:25:12
選擇地址從商店天然加入訪問在哪裏CUSID(選擇CUSID從客戶那裏CNAME ='約翰'GROUP BY CUSID具有COUNT(CUSID)> 2); – user2351750 2013-05-06 12:29:25