1

サブクエリなしでSQLクエリを作成しようとしていますが、ここに作業クエリがあります:

select * from customers 
join 
(select idContactOwner, count(*) contacts_count 
from contacts GROUP BY idContactOwner HAVING contacts_count>5) k 
where customers.id=k.idContactOwner;

ここに私がしようとしているものがありますが、うまくいきません:

select idContactOwner, count(*) counter from contacts A
group by idContactOwner having counter>5 join customers B
on A.idContactOwner=B.id;

ここにSQLフィドルがあります:

http://sqlfiddle.com/#!2/724962/59

4

2 に答える 2

3

group by後に来なければならないjoin

select A.idContactOwner, count(*) counter 
from contacts A
join customers B on A.idContactOwner = B.id
group by A.idContactOwner 
having counter > 5 
于 2013-09-08T16:18:44.373 に答える
1
SELECT A.idContactOwner, B.whatEverFields, count(A.idContactOwner) AS counter
FROM contacts A, customers B
WHERE A.idContactOwner=B.id 
GROUP BY A.idContactOwner 
HAVING counter>5;

このようなもの?

于 2013-09-08T16:20:26.833 に答える