• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
count how may records are AM vs. PM

#1
[eluser]new_igniter[/eluser]
Hello,
I have a DB with mysql a standard timestamp in the format of 2008-01-23 11:44:16

Can someone help me with the mysql syntax for counting the number of records with a time in the AM and PM. It could be 2 different queries, but I havent been able to figure it out.

#2
[eluser]Armchair Samurai[/eluser]
I'd do it like this - retrieve two records from the table, the first being AM totals and the second PM:
Code:
SELECT COUNT(*) AS `times`
FROM `foo`
WHERE HOUR(`bar`) < 12
UNION
SELECT COUNT(*)
FROM `foo`
WHERE HOUR(`bar`) >= 12

#3
[eluser]new_igniter[/eluser]
thanks so much!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.