Skip to content

Instantly share code, notes, and snippets.

@HubertArciszewski95
Last active January 30, 2018 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HubertArciszewski95/70184c36889157c036c17a5ee40b3689 to your computer and use it in GitHub Desktop.
Save HubertArciszewski95/70184c36889157c036c17a5ee40b3689 to your computer and use it in GitHub Desktop.
Syntax form test in MySQL course
SELECT
first_name,
last_name,
COUNT(rating) AS count,
IFNULL(MIN(rating),0) AS min,
IFNULL(MAX(rating), 0) AS max,
ROUND(IFNULL(AVG(rating), 0), 2) AS avg,
CASE
WHEN COUNT(rating) > 0 THEN 'ACTIVE'
ELSE 'INACTIVE'
END AS 'STATUS'
FROM reviewers
LEFT JOIN reviews
ON reviewers.id = reviews.reviewer_id
GROUP BY reviewers.id
ORDER BY rating DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment