mysql - SQL subqueries ques : -


i have these 3 tables :

1)sailors (sid:int, sname:varchar(30), rating:int, age:int)

2)boats (bid:int, bname:varchar(30), color:varchar(10))

3)reserves (bid:int, sid:int, day:date)

i don't know how build query displays : names of sailors have reserved @ least 2 boats in different colors!

you can create group each sailor, , demand there @ least 2 distinct colors in group:

select  s.sid ,       s.sname ,       count(distinct b.color) numberofboatcolorsreserved    reserves r join    sailors s on      s.sid = r.sid join    boats b on      b.bid = r.bid group         s.sid ,       s.sname having  count(distinct b.color) >= 2 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -