gpt4 book ai didi

Mysql子查询帮助

转载 作者:行者123 更新时间:2023-11-29 00:54:36 24 4
gpt4 key购买 nike

我有一个表,其中有两种类型的记录 - 更新和结束(事件类型 - 列)。

更新记录包含 PID 和网页详细信息,而结束记录包含音量(上传和下载)和 PID 详细信息(无网页详细信息:())。两种记录类型的公共(public)字段都是 PID。

现在,我需要从表中获取所有网站的 SUM(ULVolume+DLVolume)IE- 获取每个的总和(ULVo+DLVol)(获取每个的 PID(获取不同的网站))

最后,这就是我要从一个查询中寻找的内容。这里需要一些帮助。附言数据库大>10G,查询时间短者优先。

预期输出

Website     Sum(ULVolume+DLVolume)
apple.com 112343XXXXX
google.com 121232XXXXX

更新记录:

+-----------------+--------+---------------+----------+----------+
| PID | Event | Web | ULVolume | DLVolume |
+-----------------+--------+---------------+----------+----------+
| 199710687818416 | update | kaspersky.com | | |
| 199710687818417 | update | google.com | | |
| 199710687818418 | update | yahoo.com | | |
+-----------------+--------+---------------+----------+----------+

结束记录:

+-----------------+-------+------+----------+----------+
| PID | Event | Web | ULVolume | DLVolume |
+-----------------+-------+------+----------+----------+
| 199710687818416 | end | | 5187 | 309683 |
+-----------------+-------+------+----------+----------+

最佳答案

试试这个:

select
u.website,
sum(e.ULVolume + e. DLVolume) as volume
from mytable e
left join mytable u on u.PID = e.PID and u.event ='update'
where e.Event = 'end'
group by 1;

关于Mysql子查询帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6712847/

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