Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. # working right - gives 5 result
  2. SELECT R.Title FROM Restaurant R, RestaurantCategory RC, RestaurantOptions RS
  3. WHERE R.RestaurantCategoryID = RC.RestaurantCategoryID
  4. AND R.RestaurantID = RS.RestaurantID
  5. AND RC.RestaurantCategoryParentID = 185
  6. AND RS.RestaurantCategoryOptionsID IN(11,2) GROUP BY R.RestaurantID HAVING COUNT(DISTINCT RS.RestaurantCategoryOptionsID) = 2
  7. ORDER BY R.Title DESC;
  8.  
  9. # working wrong - gives me about 30 different restaurants... should give 5 as upper statement
  10. SELECT RC.Title AS Title, RC.RestaurantCategoryID AS RestaurantCategoryID,
  11. COUNT(DISTINCT R.RestaurantID) AS Total FROM Restaurant R, RestaurantCategory RC, RestaurantOptions RS
  12. WHERE R.RestaurantCategoryID = RC.RestaurantCategoryID AND R.RestaurantID = RS.RestaurantID
  13. AND RC.RestaurantCategoryParentID = 185 AND R.Status = 1
  14. AND RS.RestaurantCategoryOptionsID IN(11,2)
  15. GROUP BY RC.RestaurantCategoryID
  16. HAVING COUNT(DISTINCT RS.RestaurantCategoryOptionsID) = 2 ORDER BY RC.Title ASC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement