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. Aggregate Query...

Aggregate Query...

Scheduled Pinned Locked Moved Database
questiondatabasegame-dev
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.
  • H Offline
    H Offline
    Hyien
    wrote on last edited by
    #1

    I have the following tables: CREATE PLAYER ( PLAYERNO INT UNIQUE NOT NULL, NAME CHAR(20), ... PRIMARY KEY(PLAYERNO) ) CREATE TABLE GAME ( GAMENO INT UNIQUE NOT NULL, PLAYER1 INT, PLAYER2 INT, HOURS INT, ... PRIMARY KEY(GAMENO), FOREIGN KEY(PLAYER1) REFERENCES PLAYER(PLAYERNO), FOREIGN KEY(PLAYER2) REFERENCES PLAYER(PLAYERNO) ) How do I retrieve, for every player, the total number of hours he played as Player1 and the total number of hours played as Player2? The resulting table should be something like: PLAYERNO HRS-PLAYED-AS-P1 HRS-PLAYED-AS-P2

    M 1 Reply Last reply
    0
    • H Hyien

      I have the following tables: CREATE PLAYER ( PLAYERNO INT UNIQUE NOT NULL, NAME CHAR(20), ... PRIMARY KEY(PLAYERNO) ) CREATE TABLE GAME ( GAMENO INT UNIQUE NOT NULL, PLAYER1 INT, PLAYER2 INT, HOURS INT, ... PRIMARY KEY(GAMENO), FOREIGN KEY(PLAYER1) REFERENCES PLAYER(PLAYERNO), FOREIGN KEY(PLAYER2) REFERENCES PLAYER(PLAYERNO) ) How do I retrieve, for every player, the total number of hours he played as Player1 and the total number of hours played as Player2? The resulting table should be something like: PLAYERNO HRS-PLAYED-AS-P1 HRS-PLAYED-AS-P2

      M Offline
      M Offline
      Mazdak
      wrote on last edited by
      #2

      I guess this will work:

      select 'PLAYERNO' + game.player1 ,sum(game.hours) + 'hours played' as P1,'PLAYERNO' + game.player2 ,sum(game.hours)+'hours played' as P2 from game where gameno = @yournumber

      I'm not sure but maybe you nedd some data conversion when you add 'PLAYERNO' to game.player Mazy **"If I go crazy then will you still Call me Superman If I’m alive and well, will you be There holding my hand I’ll keep you by my side with My superhuman might Kryptonite"**Kryptonite-3 Doors Down

      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