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

Need Query.

Scheduled Pinned Locked Moved Database
database
3 Posts 3 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.
  • B Offline
    B Offline
    Binod K
    wrote on last edited by
    #1

    Hi, Anyone could provide me solution. I have table like this Date | Status -------------------------------- 12/07/08 | 2 12/07/08 | 3 12/07/08 | 3 13/07/08 | 2 13/07/08 | 3 13/07/08 | 2 ---------------------------------- I want count of status on each day. For Clear understanding output should like this Date | Total 2 | Total 3 --------------------------------- 12/07/08 | 1 | 2 13/07/08 | 2 | 1 ---------------------------------- Thanks

    Binod K. (Miles to go before I sleep)

    L B 2 Replies Last reply
    0
    • B Binod K

      Hi, Anyone could provide me solution. I have table like this Date | Status -------------------------------- 12/07/08 | 2 12/07/08 | 3 12/07/08 | 3 13/07/08 | 2 13/07/08 | 3 13/07/08 | 2 ---------------------------------- I want count of status on each day. For Clear understanding output should like this Date | Total 2 | Total 3 --------------------------------- 12/07/08 | 1 | 2 13/07/08 | 2 | 1 ---------------------------------- Thanks

      Binod K. (Miles to go before I sleep)

      L Offline
      L Offline
      leoinfo
      wrote on last edited by
      #2

      This is what you need, BUT ... next time, post some code that you tried here so we know that we are not doing all your job :)

      SELECT
      Date
      , [2] AS [Total 2]
      , [3] AS [Total 3]
      FROM YOUR_TABLE_NAME
      PIVOT (
      COUNT( Status )
      FOR Status IN ( [2] , [3] )
      ) AS p

      1 Reply Last reply
      0
      • B Binod K

        Hi, Anyone could provide me solution. I have table like this Date | Status -------------------------------- 12/07/08 | 2 12/07/08 | 3 12/07/08 | 3 13/07/08 | 2 13/07/08 | 3 13/07/08 | 2 ---------------------------------- I want count of status on each day. For Clear understanding output should like this Date | Total 2 | Total 3 --------------------------------- 12/07/08 | 1 | 2 13/07/08 | 2 | 1 ---------------------------------- Thanks

        Binod K. (Miles to go before I sleep)

        B Offline
        B Offline
        Blue_Boy
        wrote on last edited by
        #3

        select distinct [date], (select count(t1.status) from MyTable as t1 where status=2 and t1.date=MyTable.[date]) as [Total 2], (select count(t1.status) from MyTable as t1 where status=3 and t1.date=MyTable.[date]) as [Total 3] from MyTable


        I Love T-SQL "Don't torture yourself,let the life to do it for you."

        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