gpt4 book ai didi

mysql - SQL:决定使用与否

转载 作者:可可西里 更新时间:2023-11-01 07:17:12 24 4
gpt4 key购买 nike

您好:我使用 Shell 和 Python 对数据库进行了一些文本处理。对于互操作性,我正在考虑使用 SQL 来实现。 SQL 适用于某些查询任务。但我不确定 SQL 是否可以处理我的所有任务。考虑一个示例数据库:

item | time | value -----+------+------- 1   | 134  |   3 2   | 304  |   1 3   | 366  |   2 4   | 388  |   2 5   | 799  |   6 6   | 111  |   7

我需要分析特定#time 间隔内#values 的总和。假设时间间隔为100,结果应该是:

time_interval | sumvalue--------------+----------      1       |   10      -- the time interval from 100 to 199      3       |    5      -- the time interval from 300 to 399      7       |    6      -- the time interval from 700 to 799

我无法从 SQL 教科书中找到比使用 shell 和 python 更好的方法。
所以我的 friend 们,有什么建议吗?

谢谢!

最佳答案

你应该能够在 mysql 中通过一个非常简单的查询来完成它:

SELECT time DIV 100, SUM(value) FROM yourtable
GROUP BY time DIV 100

查询利用了整数除以 100 的事实,将为您提供所描述的间隔分组(例如,111 DIV 100 = 1134 DIV 100 = 1)

关于mysql - SQL:决定使用与否,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4546252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com