Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL statement help

SQL statement help

Scheduled Pinned Locked Moved Database
databasehelpcareer
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ruifernandes24
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • R ruifernandes24

      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

      G Offline
      G Offline
      Gerald Schwab
      wrote on last edited by
      #2

      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.name

      or 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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups