www.webdeveloper.com
Results 1 to 2 of 2

Thread: Help on counting

Hybrid View

  1. #1
    Join Date
    Jan 2011
    Posts
    42

    Help on counting

    WHat i am trying to do is do a sql query that counts and saves the data in a variable. Then i need to get a total of the all the vairables in the query


    Here is the SQL Query
    [SQL]
    SELECT COUNT(CASE WHEN (Youth1 ='Extra Small') THEN 1 ELSE NULL END) AS ysExtraSmall, COUNT(CASE WHEN (Youth1 ='Small') THEN 1 ELSE NULL END) AS ysSmall
    FROM DB WHERE Year1 = '2013'
    [/SQL]

    Then I need to add ysExtraSmall + ysSmall = Total
    Who do i do that?

  2. #2
    Join Date
    Jul 2013
    Posts
    29
    select *, ysExtraSmall+ysSmall as total from (
    SELECT COUNT(CASE WHEN (Youth1 ='Extra Small') THEN 1 ELSE NULL END) AS ysExtraSmall, COUNT(CASE WHEN (Youth1 ='Small') THEN 1 ELSE NULL END) AS ysSmall
    FROM DB WHERE Year1 = '2013'
    ) as z

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles