DMXzone Database Connector PHP Support Product Page
Answered
How to do this
Asked 21 Dec 2014 20:18:03
1
has this question
21 Dec 2014 20:18:03 PerOlof Johansson posted:
I want to calculate the average, homeaverage (hemmasnitt) and avayaverage (bortasnitt) from a table of results. like thisSELECT team_resultat.medlem_id, team_medlem.namn, sum(resultat)/sum(serier) as snitt,
SUM(case when not borta then resultat else 0 end) / SUM(case when not borta then serier else 0 end) as hemmasnitt,
SUM(case when borta then resultat else 0 end) / SUM(case when borta then serier else 0 end) as bortasnitt, sum(banp) AS banp
FROM team_resultat
JOIN team_medlem ON team_resultat.medlem_id = team_medlem.medlem_id
JOIN team_samling ON team_resultat.match_id = team_samling.match_id
WHERE datum >= current_date - interval '1' year
GROUP BY namn
ORDER BY ".$sortorder[$sort] );
I am clueless how to build this query using the features available in your Database Source Query Builder.
Can I use UNION ALL to add up the columns like this:
SELECT team_resultat.medlem_id, team_medlem.namn, serie1 as serie FROM team_resultat LEFT JOIN team_medlem ON team_resultat.medlem_id = team_medlem.medlem_id UNION ALL
SELECT team_resultat.medlem_id, team_medlem.namn, serie2 as serie FROM team_resultat LEFT JOIN team_medlem ON team_resultat.medlem_id = team_medlem.medlem_id UNION ALL
SELECT team_resultat.medlem_id, team_medlem.namn, serie3 as serie FROM team_resultat LEFT JOIN team_medlem ON team_resultat.medlem_id = team_medlem.medlem_id UNION ALL
SELECT team_resultat.medlem_id, team_medlem.namn, serie4 as serie
FROM team_resultat
LEFT JOIN team_medlem ON team_resultat.medlem_id = team_medlem.medlem_id
JOIN team_samling ON team_resultat.match_id = team_samling.match_id
WHERE datum >= current_date - interval '1' year
ORDER BY serie desc
LIMIT 5
How to do this?
Replies
Replied 05 Jan 2015 10:12:39
05 Jan 2015 10:12:39 Teodor Kuduschiev replied:
Hello,
If you need to calculate average(s) or make any other calculations, you need the HTML5 Data Bindings Formatter: www.dmxzone.com/go/22124/html5-data-bindings-formatter
If you need to calculate average(s) or make any other calculations, you need the HTML5 Data Bindings Formatter: www.dmxzone.com/go/22124/html5-data-bindings-formatter
Replied 05 Jan 2015 19:15:05
05 Jan 2015 19:15:05 PerOlof Johansson replied:
Read the questions again.
How do I do this (sum(resultat)/sum(serier) as snitt) resultat and serier are two columns in the database.
and
Can I use UNION ALL to add up the columns like this: see above
I want a sql window to type in SQL code.
How do I do this (sum(resultat)/sum(serier) as snitt) resultat and serier are two columns in the database.
and
Can I use UNION ALL to add up the columns like this: see above
I want a sql window to type in SQL code.