locked
Urgently need mysql query for the case below RRS feed

  • Question

  • User142981640 posted
    Hi All , I am new to mySQL , here is a sample data of my table :
    
    |     Run     |     End Date   |
    ---------------------------------
       Passed     |    1/30/2014   |
       Passed     |    1/30/2014   |
       Failed     |    1/31/2014   |
       Passed     |    1/28/2014   |
       Passed     |    2/10/2014   |
       Failed     |    2/12/2014   |
       Passed     |    2/12/2014   |
       Passed     |    12/9/2013   |
       Passed     |    12/10/2013  |
       Failed     |    12/18/2013  |
       Not Run    |                |
       Passed     |    12/18/2013  |
       Passed     |    12/17/2013  |
       Passed     |    12/17/2013  |
       Passed     |    12/16/2013  |
       Passed     |    12/16/2013  |
    ------------------------------------
    
    I want an mySQL query which will give me out put data containing :
    
    
    Number of pass | Number of Fail | Not run | Date          |
    ----------------------------------------------------------
      10           |     2           |   1     | 12/16/2013   |
    ----------------------------------------------------------
    
    
    ie . [ Pass / fail /not run ] for each day
    
    
    
    
    
    Tuesday, March 25, 2014 5:58 AM

All replies

  • User1208776063 posted

    SELECT Sum(CASE
                 WHEN run = 'Passed' THEN 1
                 ELSE 0
               end) Pass,
           Sum(CASE
                 WHEN run = 'Failed'THEN 1
                 ELSE 0
               end) Fail,
           Sum(CASE
                 WHEN run = 'Not Run' THEN 1
                 ELSE 0
               end) [Not Run],
           datecolumn
    FROM   tablename
    GROUP  BY datecolumn  

    Tuesday, March 25, 2014 6:45 AM