dsmnedc798226 2010-12-06 22:27
浏览 120

在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条回答 默认 最新

  • dongxian3852 2010-12-06 22:43
    关注
    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
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题