0

I have a table psttodo-uit with some fields like Hostess Code, Datum Bezoek 1, PA, PB, PG, GoedkeuringDoorNew, Blanco, .. .

Now I would like to select all the fields where Hostess Code is equal to ... . I want an overview like this:

1 march  |   info     info     info
2 march  |   info     info     info

But in my table I have :

2014-04-03 11:32:18
2014-04-03 11:22:16
2014-04-02 16:05:22
2014-04-02 15:40:43
2014-04-02 15:17:41

So I would like to select for each day and make a count of the other fields like count(PA = 1). Can I do this in one SQL Query?

1

4 Answers 4

2

Your select has to be something like:

select `Hostess Code`, DATE_FORMAT(`Datum Bezoek 1`, '%e %M'), count(PA), count(PB), count(PG), GoedkeuringDoorNew, Blanco,... where ... group by DATE_FORMAT(`Datum Bezoek 1`, '%e %M') order by DATE_FORMAT(`Datum Bezoek 1`, '%e %M')

I hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

0

Something like:

SELECT DATE_FORMAT(DT, '%e %M')
, COUNT(PA) PA_COUNT
, COUNT(PB) PB_CCOUNT
...
FROM 
YOUR_TABLE
GROUP BY DATE_FORMAT(DT, '%e %M')

Comments

0

Try this:

 Select DATE(date_column), col1, col2 
 from psttodo-uit 
 group by DATE(date_column)
 order by DATE(date_column)

Comments

0

You can do this by grouping the dates using the DATE() function and then count the conditions on the other fields using a sum(case when condition then 1 else 0 end), like this

SELECT DATE(`Datum Bezoek 1`) as MyDate, sum(case when PA=1 then 1 else 0 end) as PA1, count(case when PB=2 then 1 else 0 end) as PB2, other fields here...
FROM yourtablename
WHERE `Hostess Code`=value
GROUP BY DATE(`Datum Bezoek 1`)

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.