Advertisement
byu

With Clause (for aliases)

byu
Oct 20th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.54 KB | None | 0 0
  1. with    rc(model,make,manufacturer,yr,recallid,compdesc,potential) as(
  2.     select modelname,makename,manufacturer,yeartxt,rmy.recallid,compdesc,potential
  3.     from recall.model mo
  4.     join recall.make ma on mo.makeid=ma.makeid
  5.     join recall.recall_modelyear rmy on rmy.modelid = mo.modelid
  6.     join recall.recall r on rmy.recallid = r.recallid
  7. )
  8.  
  9. select manufacturer, yr, count(*) as totalRecall, max(potential) as biggestRecall from rc
  10.  
  11. group by manufacturer, yr
  12. having count(*) >= 10 and  max(potential) < 2000000
  13. order by totalrecall desc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement