-1

I'm trying to create a query that would return a table as followed:

  1. dayName, #ofStatus1,#ofStatus2,#ofStatus3
  2. dayName, #ofStatus1,#ofStatus2,#ofStatus3
  3. dayName, #ofStatus1,#ofStatus2,#ofStatus3
  4. dayName, #ofStatus1,#ofStatus2,#ofStatus3
  5. dayName, #ofStatus1,#ofStatus2,#ofStatus3
  6. dayName, #ofStatus1,#ofStatus2,#ofStatus3
  7. dayName, #ofStatus1,#ofStatus2,#ofStatus3

Basically I have a table where users get to enter cases. Each case has the following fields(datedCreated, status).

There are three (3) status possible (new, progress, closed)

So I would like to retrieve the number of each status for each day.

Each line would look something like this:

  1. Monday, 8,3,2
  2. Tuesday, 8,3,2
  3. Wednesday, 8,3,2
  4. ...

I have something that looks like this but can't seem to get it to work.

SELECT DAYNAME(dateAdded)AS Date, COUNT(status) AS Count, GROUP_CONCAT(CONCAT(status, ',', "54") SEPARATOR ',' ) AS Text FROM clients GROUP BY DATE(dateAdded) ORDER BY dateAdded LIMIT 7

I know right now I have three colomns, but I need it to be in one columns.

Thank your for the help in advance.

0

2 Answers 2

0

Try:

SELECT concat(
       DAYNAME(dateAdded),', '
       sum(case when status = 'new' then 1 else 0 end),','
       sum(case when status = 'progress' then 1 else 0 end),','
       sum(case when status = 'closed' then 1 else 0 end)) as single_col
  FROM clients
 GROUP BY DATE(dateAdded)
 ORDER BY dateAdded
1
  • Thanks for answering, the query was missing commas after each SUM (otherwise it wouldn't run) but even then, the result is unreadable. I get like: 4d6f6e6461792c302c312c31, 547565736461792c312c302c31, 5765646e65736461792c302c312c30 as a result.
    – onlymushu
    Sep 8, 2014 at 10:15
0

Why not just group concat the results?

SELECT
    GROUP_CONCAT(t_date, t_new, t_progress, t_closed) AS 'Status Per Day'
FROM
(   SELECT 
        DAYNAME(dateAdded)AS t_date,
        SUM(status = 'new') t_new, 
        SUM(status = 'progress') t_progress,
        SUM(status = 'closed') t_closed 
    FROM clients 
    GROUP BY DATE(dateAdded) 
    ORDER BY dateAdded LIMIT 7
) t
GROUP BY t_date
2
  • It seems to return [BLOB - 69 B]
    – onlymushu
    Sep 8, 2014 at 10:18
  • @onlymushu oops sorry forgot to add the group by.. try it now. Sep 8, 2014 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.