在sql中我可以对结果集进行分组,以找出每组的百分比

I would like to know if I do a query like this

Select pass_fail, timestamp 
from test_execution 
where site = 'test' and timestamp between '1234567890' and '1234567890'  

Let's say this query returns 96 results because the timestamp are a 24 hour period and there's 4 results per hour. With this how can I find out the percentage of pass_fail for each hour in that 24 hour period.( there's 4 results per hour in those 24 hours so 96 total how can I find how many pass for each hour ) would I need to group results?

Would I need to Limit 4 offset 0 then increase the offset by 4 each run and average each set like that? It just seems wrong that way...any suggestions?

Thanks

  1. add an "hour" column
  2. put entire query in a subselect
  3. in outer select, group by hour
  4. in outer select, compute the % of passes as # of passes / count(*) * 100