Guest User

Untitled

a guest
Dec 12th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. # get all students last_name, alphabetically ordered, not repeating
  2. SELECT DISTINCT last_name
  3. FROM students
  4. ORDER BY last_name
  5.  
  6. # get the count of all students in each groups, order by groups names descending
  7. SELECT groups.name,
  8. Count(students.id)
  9. FROM groups
  10. LEFT JOIN students
  11. ON groups.id = students.group_id
  12. GROUP BY groups.name
  13. ORDER BY groups.name DESC
  14.  
  15. # get the list of students with duplicate first_names. Order alphabetically
  16. SELECT DISTINCT ls.first_name,
  17. ls.last_name
  18. FROM students AS ls
  19. INNER JOIN students AS rs
  20. ON ( ls.first_name = rs.first_name
  21. AND ls.id != rs.id )
  22. ORDER BY ls.first_name
  23.  
  24. # get list of all groups names, ordered by sum of max rating of students
  25. SELECT groups.NAME, coalesce(sum(students.rating), 0) as gr_rating
  26. FROM groups
  27. LEFT JOIN students # может быть INNER JOIN в зависимости от конкретизации задачи
  28. ON groups.id = students.group_id
  29. GROUP BY groups.NAME
  30. ORDER BY gr_rating
  31.  
  32. # get list of all students with first_name ‘F’
  33. SELECT *
  34. FROM students
  35. where SUBSTRING(first_name, 1, 1) = 'F'
Add Comment
Please, Sign In to add comment