Difference between revisions of "SQL query examples"

From TempusServa wiki
Jump to navigation Jump to search
old>Admin
(Created page with " === Lookup related data === SELECT l.`Value`, COUNT(k.DataID) FROM data_kuglespil as k JOIN formfieldlookup as l ON k.STRRELSE = l.LookupID; === Grouped variables ==...")
 
old>Admin
Line 1: Line 1:
=== Status related data ===
  SELECT s.Status, COUNT(k.DataID)
  FROM data_kuglespil as k
  JOIN formstatus as s ON k.StatusID = s.StatusID
  GROUP BY 1;


=== Lookup related data ===
=== Lookup related data ===
Line 4: Line 11:
   SELECT l.`Value`, COUNT(k.DataID)
   SELECT l.`Value`, COUNT(k.DataID)
   FROM data_kuglespil as k
   FROM data_kuglespil as k
   JOIN formfieldlookup as l ON k.STRRELSE = l.LookupID;
   JOIN formfieldlookup as l ON k.STRRELSE = l.LookupID
 
  GROUP BY 1
  ORDER BY l.SortOrder;


=== Grouped variables ===
=== Grouped variables ===

Revision as of 09:07, 17 September 2018

Status related data

 SELECT s.Status, COUNT(k.DataID)
 FROM data_kuglespil as k
 JOIN formstatus as s ON k.StatusID = s.StatusID
 GROUP BY 1;

Lookup related data

 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;