I have two tables: One with just a list of dates called date_range (column name is Date) and one called wp_wpdatatable_1 in which all the date is stored (after each practice, a row for every player is created with the name of the player (player), date of practice (date), duration (sporttrainingduration), what practice group (practiceheldby) etc...
Now I want to create a report.
I want every day of the month across, the players names in the first column and on every day a player was at a practice I want to list which practice he attended (wp_wpdatatable_1.practiceheldby)
-- 1. Create an expression that builds the columns
set @sql = (
select group_concat(distinct
concat(
"max(case when date_range.`date`='", date_range.`Date`, "' then `practiceheldby` end) as `", date_range.`Date`, "`"
)
)
from wp_wpdatatable_1, date_range
where date_range.`Date`>=2019-06-01
and date_range.`Date` <= 2019-06-07
);
-- 2. Complete the SQL instruction
set @sql = concat("select `player`, ", @sql , " from wp_wpdatatable_1 group by `player`");
-- 3. Create a prepared statement
PREPARE stmt from @sql;
-- 4. Execute the prepared statement
execute stmt;
DEALLOCATE PREPARE stmt;
I'm not a pro and I've played with this for 3 or four days now. I think I'm very close, but I get this error message:
PREPARE stmt from @sql MySQL meldet: Dokumentation
#1064 - Fehler in der SQL-Syntax. Bitte die korrekte Syntax im Handbuch nachschlagen bei 'NULL' in Zeile 1
What am I missing? thank you!