Difference between revisions of "SQL query examples"
Jump to navigation
Jump to search
old>Admin |
old>Admin |
||
Line 1: | Line 1: | ||
== Grouping == | |||
=== Status related data === | === Status related data === | ||
Line 32: | Line 33: | ||
FROM data_kuglespil as k | FROM data_kuglespil as k | ||
WHERE k.RESULTAT = 17; | WHERE k.RESULTAT = 17; | ||
== Corner cases == | |||
=== List of birthdays === | === List of birthdays === |
Revision as of 18:34, 19 March 2019
Grouping
SELECT s.Status, COUNT(k.DataID) FROM data_kuglespil as k JOIN formstatus as s ON k.StatusID = s.StatusID GROUP BY 1;
SELECT l.`Value`, COUNT(k.DataID) FROM data_kuglespil as k JOIN formfieldlookup as l ON k.STRRELSE = l.LookupID GROUP BY 1 ORDER BY l.SortOrder;
Grouped variables
SELECT 'Under 5' as Text, COUNT(k.DataID) FROM data_kuglespil as k WHERE k.RESULTAT <= 5 UNION SELECT 'Middel (6-16)' as Text, COUNT(k.DataID) FROM data_kuglespil as k WHERE k.RESULTAT <= 5 AND k.RESULTAT < 17 UNION SELECT 'Top performer (17)' as Text, COUNT(k.DataID) FROM data_kuglespil as k WHERE k.RESULTAT = 17;
Corner cases
List of birthdays
SELECT NAVN as Navn, FDSELSDAG as Fødselsdag, ROUND(DATEDIFF(NOW(),FDSELSDAG) / 365 ) as Alder FROM data_medarbejder WHERE DATEDIFF( MAKEDATE(YEAR(NOW()),DAYOFYEAR(FDSELSDAG)), NOW() ) BETWEEN 0 AND 7