2016-07-24 5 views

Antwort

1

Gruppe durch die courseId und wählen Sie nur diejenigen diese

select courseId 
from your_table 
where categoryId in (18112,21115) 
group by courseId 
having count(distinct categoryId) = 2 
+0

> = 2, nicht = 2, er sagte "2 oder mehr als 2" –

+0

die WHERE-Klausel wählt nur die 2 –

1
select courseId 
from courses_categories 
where categoryId in (18112,21115) 
group by courseId 
having count(distinct categoryId) >= 2 
+0

gleich 2 auch benötigt. wenn ja, "count (distinct categoryId)> = 2" – Sankar

1

Group by und Having Klauseln s 2 categoryId mit Wille hilft Ihnen.

select courseId 
from your_table 
where categoryId in (18112,21115) 
group by courseId 
having count(distinct categoryId) >= 2 
1

können Sie GROUP BY und HAVING wie unten verwenden:

SELECT courseId 
FROM table_name 
WHERE categoryId IN (18112,21115) 
GROUP BY courseId 
HAVING COUNT(DISTINCT categoryId) >= 2