diff options
| author | horus | 2022-12-13 14:39:00 +0100 |
|---|---|---|
| committer | horus | 2022-12-13 14:39:00 +0100 |
| commit | fb617e02cab09a5fb7c680f15aa91e17a7fbb811 (patch) | |
| tree | 6a775d1bda7baf5f2165ecf3c9529175b4319c43 /functions.php | |
| parent | 8d45c8fc94b1ee7c8b1779075b8f332fb137b8d3 (diff) | |
| download | hochzeit-fb617e02cab09a5fb7c680f15aa91e17a7fbb811.tar.gz | |
Stats!
Diffstat (limited to 'functions.php')
| -rw-r--r-- | functions.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/functions.php b/functions.php index e31ce0f..3444bf9 100644 --- a/functions.php +++ b/functions.php @@ -126,3 +126,49 @@ function getData($db, $familien_id = null) { } return $stmt->fetchAll(); } + +function getStats($db) { + $query = " +with freie_plätze as ( +select sum(auto_freie_plätze) as freie_plätze, +SUM(CASE WHEN kommt_mit_auto = 0 + THEN 1 + ELSE 0 END) AS kommt_ohne_auto, +SUM(CASE WHEN kommt_mit_auto = 2 + THEN 1 + ELSE 0 END) AS kommt_eventuell_mit_auto, +SUM(kommt_mit_auto) as auto_zusage +from familie +) +select +freie_plätze, +auto_zusage as kommt_mit_auto, +kommt_ohne_auto, +kommt_eventuell_mit_auto, +sum(zusage) as zusage, +SUM(CASE WHEN f.kommt_mit_auto = 0 + OR f.kommt_mit_auto = 2 + THEN 1 + ELSE 0 END) AS benötigte_auto_plätze, +SUM(CASE WHEN zusage = 0 + THEN 1 + ELSE 0 END) AS absage, +SUM(CASE WHEN essenwahl = 0 + THEN 1 + ELSE 0 END) AS ente, +SUM(CASE WHEN essenwahl = 1 + THEN 1 + ELSE 0 END) AS vegetarisch, +SUM(CASE WHEN essenwahl = 2 + THEN 1 + ELSE 0 END) AS vegan, +SUM(CASE WHEN essenwahl = 3 + THEN 1 + ELSE 0 END) AS kinderteller + from familie f join gästeliste g on f.id = familien_id join freie_plätze +"; + $stmt = $db->prepare($query); + $stmt->execute(); + + return $stmt->fetchAll(); +} |
