mysql - Query based off one element -
i given following database schema
cows (cowid, cowname, cowage) cowpurchaser (purchaserid, name, address) purchaserecord (purchaserid, cowid, year)
for each year, cow purchaser "farmland" purchased atleast 1 cow, find number of cows purchased. output set of tuples, indicates year , number of cows purchased "farmland"
i not sure how approach this. tried
select (pr.year, count(c.name)) purchaserecord pr, cowpurchaser cp, cows c cp.name = "farmland" , count(c.name) >= 1
this not giving result want. doing wrong? how can fix it?
select pr.year, count(c.name) purchaserecord pr inner join cowpurchaser cp on pr.purchaserid=cp.purchaserid inner join cows c on pr.cowid=c.cowid cp.name = "farmland" group pr.year having count(c.name) >= 1
Comments
Post a Comment