Hello world,
I'm creating a database in a music teaching environment. It creates a schedule which can be saved as an iCalendar .ics file. I already got this working, but I'm struggling in extending my SQL statement to number the lessons.
I have two tables:
- "Stammdaten", which contain all students and their weekly time which they booked (e.g. Monday, 14:00-14:45, always one student per time)
- "Kalender", containing every day of the years 2024/2025/2026 and its boolean status whether it's a school day (lessons happens only outside school holidays and bank holidays)
I get my schedule via this working SQL statement:
SELECT "Kalender"."ID", "Stammdaten"."Nachname", "Stammdaten"."Vorname", "Kalender"."Datum", "Stammdaten"."Unterrichszeitbeginn", "Stammdaten"."Unterrichtsdauer", "Stammdaten"."Fach", "Stammdaten"."Wochen", "Stammdaten"."Anzahl Stunden"
FROM "Kalender" AS "Kalender"
CROSS JOIN "Stammdaten" AS "Stammdaten"
WHERE "Kalender"."Unterrichtstag" = TRUE AND ( "Kalender"."Datum" >= "Stammdaten"."Belegungsbeginn" ) AND ( "Kalender"."Datum" <= "Stammdaten"."Belegungsende" ) AND "Stammdaten"."Unterrichtswochentag" = DAYOFWEEK( "Kalender"."Datum" )
AND ( ( "Stammdaten"."Wochen" = 'Jede' ) OR ( "Stammdaten"."Wochen" = 'Gerade' AND MOD( WEEK( "Kalender"."Datum" ), 2 ) = 0 ) OR ( "Stammdaten"."Wochen" = 'Ungerade' AND MOD( WEEK( "Kalender"."Datum" ), 2 ) = 1 ) )
This gives me a schedule showing each lesson in the future. Now I want to number the lessons: the query should add a column where the student's first lessons gets a 1, the second a 2 and so on.
I saw this thread viewtopic.php?t=99451 and tried to adapt the method, but it gives no strict incremental numbering when there are gaps in the original data.
Any hints would be much appreciated.
Harald
I'm creating a database in a music teaching environment. It creates a schedule which can be saved as an iCalendar .ics file. I already got this working, but I'm struggling in extending my SQL statement to number the lessons.
I have two tables:
- "Stammdaten", which contain all students and their weekly time which they booked (e.g. Monday, 14:00-14:45, always one student per time)
- "Kalender", containing every day of the years 2024/2025/2026 and its boolean status whether it's a school day (lessons happens only outside school holidays and bank holidays)
I get my schedule via this working SQL statement:
SELECT "Kalender"."ID", "Stammdaten"."Nachname", "Stammdaten"."Vorname", "Kalender"."Datum", "Stammdaten"."Unterrichszeitbeginn", "Stammdaten"."Unterrichtsdauer", "Stammdaten"."Fach", "Stammdaten"."Wochen", "Stammdaten"."Anzahl Stunden"
FROM "Kalender" AS "Kalender"
CROSS JOIN "Stammdaten" AS "Stammdaten"
WHERE "Kalender"."Unterrichtstag" = TRUE AND ( "Kalender"."Datum" >= "Stammdaten"."Belegungsbeginn" ) AND ( "Kalender"."Datum" <= "Stammdaten"."Belegungsende" ) AND "Stammdaten"."Unterrichtswochentag" = DAYOFWEEK( "Kalender"."Datum" )
AND ( ( "Stammdaten"."Wochen" = 'Jede' ) OR ( "Stammdaten"."Wochen" = 'Gerade' AND MOD( WEEK( "Kalender"."Datum" ), 2 ) = 0 ) OR ( "Stammdaten"."Wochen" = 'Ungerade' AND MOD( WEEK( "Kalender"."Datum" ), 2 ) = 1 ) )
This gives me a schedule showing each lesson in the future. Now I want to number the lessons: the query should add a column where the student's first lessons gets a 1, the second a 2 and so on.
I saw this thread viewtopic.php?t=99451 and tried to adapt the method, but it gives no strict incremental numbering when there are gaps in the original data.
Any hints would be much appreciated.
Harald
Statistics: Posted by HaraldS — Sat May 04, 2024 12:05 am