user3591637
user3591637

Reputation: 499

How to count data depending on the date?

I have a query that get that I get the COUNT of a employee where execoffice_status =1 and it works:

SELECT employeedept, execoffice_status, employee ,COUNT(*) AS 'employeetotal'
    FROM CSEReduxResponses
    WHERE execoffice_status = 1
    GROUP BY execoffice_status, employee,employeedept

What I would like to do is get the COUNT depending on the date of execoffice_date which i have try to do here:

SELECT employeedept, execoffice_status, YEAR_cse =YEAR(execoffice_date),employee ,COUNT(*) AS 'employeetotal'
FROM CSEReduxResponses
WHERE execoffice_status = 1
GROUP BY execoffice_status, employee,employeedept,execoffice_date

I would like to get it by date which with the new query I wrote doesnt get me the information I would like. Which is to give me COUNT depending on what year execoffice_date is .What is doing is giving me It doesn't even make sense to me.

I created a dummy table , I can't put it on sqlfiddle (don't know any other place else to put it ) because is not sqlfiddle is not working properly, must be down.

 create table CSEReduxResponses (employeedept int, execoffice_status int, employee int, execoffice_date datetime);
    insert into (employeedept , execoffice_status , employee , execoffice_date )
    values (1,1,10,'2014-05-08'),
    (1,1,10,'2014-05-08'),
    (1,1,10,'2014-05-08'),
    (2,2,11,'2014-05-08'),
    (2,2,11,'2015-05-08'),
    (2,2,11,'2015-05-08'),
    (2,2,11,'2015-05-08'),
    (2,2,11,'2015-04-08');

From the data above i would like to get

employeedept | execoffice_status | employee | totalstars | year_cse
--------------------------------------------------------------------
1            | 1                  | 10      |3          |2014
2            | 1                  | 11      |1           |2014
2            | 1                  | 11      |4           |2015

Upvotes: 0

Views: 53

Answers (2)

comfortablydrei
comfortablydrei

Reputation: 316

Update: Made changes based on new information

SELECT employeedept, execoffice_status, employee, COUNT(*) AS 'totalstars', YEAR_cse =YEAR(execoffice_date)
FROM CSEReduxResponses
WHERE execoffice_status = 1
GROUP BY employeedept, execoffice_status, YEAR(execoffice_date), employee 

Upvotes: 1

wvdz
wvdz

Reputation: 16651

If this is not correct you should try to specify more clearly what you want, including sample data and desired results.

SELECT execoffice_date, COUNT(*) AS 'employeetotal'
    FROM CSEReduxResponses
    GROUP BY execoffice_date;

Upvotes: 0

Related Questions