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. Count problem

Count problem

Scheduled Pinned Locked Moved Database
databasehelp
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.
  • N Offline
    N Offline
    Nishad85
    wrote on last edited by
    #1

    Hi I have a table named StudentResult UserID School Semester Grade Campus Status 1 School1 Summer 10 Campus1 Accepted 2 School1 Summer 10 Campus1 Accepted 3 School1 Summer 10 Campus1 Rejected 4 School1 Summer 10 Campus1 Rejected 5 School1 FALL 10 Campus1 Accepted 6 School1 Summer 12 Campus1 Accepted 7 School1 Summer 12 Campus1 Rejected 8 School1 Summer 12 Campus1 Accepted 9 School1 Summer 12 Campus1 Rejected 10 School1 Summer 12 Campus1 Accepted 11 School1 FALL 12 Campus1 Rejected 12 School1 FALL 12 Campus1 Accepted 13 School1 FALL 11 Campus1 Rejected 14 School1 FALL 11 Campus1 Accepted 15 School1 FALL 11 Campus1 Accepted 16 School1 Summer 11 Campus1 Rejected 17 School1 Summer 11 Campus1 Accepted 18 School1 Summer 11 Campus1 Accepted I want to take the number of accepted and rejected users from the above table as the result table below.I want to consider grade,Campus and semester for taking count and the result should be like result table.Please help me to write Query for this. I am using SQL server2000. as database School Semester Grade Campus NoofAccepted NoofRejected School1 Summer 10 Campus1 2 2 School1 Fall 10 Campus1 1 0 School1 Summer 11 Campus1 2 1 School1 Fall 11 Campus1 2 1 School1 Summer 12 Campus1 3 2 School1 Fall 12 Campus1 1 1 Thanx

    _ 1 Reply Last reply
    0
    • N Nishad85

      Hi I have a table named StudentResult UserID School Semester Grade Campus Status 1 School1 Summer 10 Campus1 Accepted 2 School1 Summer 10 Campus1 Accepted 3 School1 Summer 10 Campus1 Rejected 4 School1 Summer 10 Campus1 Rejected 5 School1 FALL 10 Campus1 Accepted 6 School1 Summer 12 Campus1 Accepted 7 School1 Summer 12 Campus1 Rejected 8 School1 Summer 12 Campus1 Accepted 9 School1 Summer 12 Campus1 Rejected 10 School1 Summer 12 Campus1 Accepted 11 School1 FALL 12 Campus1 Rejected 12 School1 FALL 12 Campus1 Accepted 13 School1 FALL 11 Campus1 Rejected 14 School1 FALL 11 Campus1 Accepted 15 School1 FALL 11 Campus1 Accepted 16 School1 Summer 11 Campus1 Rejected 17 School1 Summer 11 Campus1 Accepted 18 School1 Summer 11 Campus1 Accepted I want to take the number of accepted and rejected users from the above table as the result table below.I want to consider grade,Campus and semester for taking count and the result should be like result table.Please help me to write Query for this. I am using SQL server2000. as database School Semester Grade Campus NoofAccepted NoofRejected School1 Summer 10 Campus1 2 2 School1 Fall 10 Campus1 1 0 School1 Summer 11 Campus1 2 1 School1 Fall 11 Campus1 2 1 School1 Summer 12 Campus1 3 2 School1 Fall 12 Campus1 1 1 Thanx

      _ Offline
      _ Offline
      _Damian S_
      wrote on last edited by
      #2

      select School, Semester, Grade, Campus, sum(CASE WHEN Status = 'Accepted' THEN 1 ELSE 0 END) AS NumOfAccepted, sum(CASE WHEN Status = 'Rejected' THEN 1 ELSE 0 END) AS NumOfRejected from StudentResult group by School, Semester, Grade, Campus Of course, this is what you have asked for, but not necessarily the best way of going about it... you could always just use count (*) and use the Status as a Column heading also...

      ------------------------------------------- Don't walk in front of me, I may not follow; Don't walk behind me, I may not lead; Just bugger off and leave me alone!!

      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