SQL statement help
-
Hi I need help on a SQL statement (I'm on first steps in the world of SQL) I have 3 tables LG (id_lg, name) LineLG (id_linelg, id_lg, job, type_of_hour, monday, tuesday, ..., sunday) Type_of_hour(type_of_hour) I need to build an sql statement that retrives: the id_lg, name, normal, Outdoor, after_hours where normal, Outdoor, after_hours are the type of hours and I need for each LG the total of normal, outdoor and after_hours hours wich is listed in Table lineLG Thanks
-
Hi I need help on a SQL statement (I'm on first steps in the world of SQL) I have 3 tables LG (id_lg, name) LineLG (id_linelg, id_lg, job, type_of_hour, monday, tuesday, ..., sunday) Type_of_hour(type_of_hour) I need to build an sql statement that retrives: the id_lg, name, normal, Outdoor, after_hours where normal, Outdoor, after_hours are the type of hours and I need for each LG the total of normal, outdoor and after_hours hours wich is listed in Table lineLG Thanks
Is this what your looking for?
SELECT LG.id_lg,
LG.name,
SUM(LGL.type_of_hour) AS sum_of_hourtypes
FROM LG AS LG
JOIN LineLG AS LGL
ON LGL.id_lg = LG.id_lg
GROUP BY LG.id_lg,
LG.name
ORDER BY LG.nameor this:
SELECT LG.id_lg,
LG.name,
COUNT(LGL.type_of_hour) AS count_of_hourtypes
FROM LG AS LG
JOIN LineLG AS LGL
ON LGL.id_lg = LG.id_lg
GROUP BY LG.id_lg,
LG.name
ORDER BY LG.name