I have a table which had two types of records - update an开发者_如何学Pythond end (EventType - Column).
The Update record has the PID and webpage details where as the end record has the volume (upload and download) and PID detail (no web page detail:(). The common field for the both of the record types are PID.
Now from the table, I need to get the SUM(ULVolume+DLVolume) for all of the websites i.e - get sum(ULVo+DLVol) of each (get PID of each (get distinct websites))
At the end, this is what i am looking for from one single query.Need some help here. P.S. The database is huge >10G and query which takes less time wud be preferred.
Expected Output
Website Sum(ULVolume+DLVolume)
apple.com 112343XXXXX
google.com 121232XXXXX
Update Record:
+-----------------+--------+---------------+----------+----------+
| PID | Event | Web | ULVolume | DLVolume |
+-----------------+--------+---------------+----------+----------+
| 199710687818416 | update | kaspersky.com | | |
| 199710687818417 | update | google.com | | |
| 199710687818418 | update | yahoo.com | | |
+-----------------+--------+---------------+----------+----------+
End Record:
+-----------------+-------+------+----------+----------+
| PID | Event | Web | ULVolume | DLVolume |
+-----------------+-------+------+----------+----------+
| 199710687818416 | end | | 5187 | 309683 |
+-----------------+-------+------+----------+----------+
Try this:
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;
精彩评论