How to find doubles with SQL? -


this question has answer here:

using chinook test database wrote sql statement show tracks ordered 2 specific customers:

select inv.billingcity,cus.lastname,tra.name invoice inv join customer cus on inv.customerid=cus.customerid join invoiceline inl on inv.invoiceid=inl.invoiceid join track tra on tra.trackid=inl.trackid cus.lastname in ('schneider','schröder') order inv.billingcity,cus.lastname,tra.name 

i see there track ordered twice 1 customer:

enter image description here

how write sql statement find doubles this, i.e. "return tracks ordered multiple times 1 customer"?

try this:

select cus.customerid,tra.name,count(cus.customerid) tot invoice inv join customer cus on inv.customerid=cus.customerid join invoiceline inl on inv.invoiceid=inl.invoiceid join track tra on tra.trackid=inl.trackid group cus.customerid,tra.name having tot > 1 

Comments