avatar
问个SQL问题# Database - 数据库
mb
1
☆─────────────────────────────────────☆
didochili (didochili) 于 (Fri Nov 21 17:01:58 2008) 提到:
刚听说我还不相信.刚买了个东西,果然马上CB就进PAYPAL帐号了.
找到了以下在fatwallet上的关于这个新规定:
For what it's worth, someone posted the following in SD's forum:eBay/Live
Search CashBack V2 was launched yesterday. eBay and PayPal will determine if
CashBack eligible purchases will receive either instant CashBack or will
need to go through the 60 day pending period. Microsoft will not have a say
in the decision. You will not know if t
avatar
a*u
2
有3个表, cutomer (custid,custname, address) Product (Productid,
productname, category), sales (custid, productid)
现在要找出把所有产品都买过的客人,请问要怎么办啊
谢谢
avatar
B*g
3
http://www.w3schools.com/sql/sql_having.asp

【在 a*********u 的大作中提到】
: 有3个表, cutomer (custid,custname, address) Product (Productid,
: productname, category), sales (custid, productid)
: 现在要找出把所有产品都买过的客人,请问要怎么办啊
: 谢谢

avatar
g*l
4
这个要PIVOT一下,你要填这个表
P1 P2 P3 P4 P5 ..PN
C1
C2
C3
.
CN.
avatar
c*i
5
select custid
from sales
group by custid
having count(productid) = (select count(productid) from product)
avatar
B*g
6
we can assume productid is pk in product table.
usually in sales table custid, productid is not unique.

【在 c**i 的大作中提到】
: select custid
: from sales
: group by custid
: having count(productid) = (select count(productid) from product)

avatar
g*l
7
要做一个
SELECT DISTINCT CUSTID, PORDUCTID FROM SALE
才能用上面的QUERY
avatar
a9
8
到少要distinct一下吧,呵呵。

【在 c**i 的大作中提到】
: select custid
: from sales
: group by custid
: having count(productid) = (select count(productid) from product)

avatar
c*i
9

If custid, productid is not unique in sales table. Change the query to:
select custid
from sales
group by custid
having count(distinct productid) = (select count(productid) from product)

【在 B*****g 的大作中提到】
: we can assume productid is pk in product table.
: usually in sales table custid, productid is not unique.

avatar
y*w
10
不用count,
select distinct custid from sale s1 where not exists ( select 1 from sale
s2 right join prod p on s2.pid = p.pid and s1.custid = s2.custid where s2.
pid is null)
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。