[英]trying to get count statistics for simple db table
我想從一個簡單的數據庫表中提取名稱,#kills,#deaths。
桌子有
_from(殺手),_to(死亡的人),然后是事件的竊聽。 在pvp的情況下,我們想要計算這個人是否死亡或者被殺死並將其添加到他們的總數中
這可以通過查詢完成,還是我必須編寫腳本? 這不起作用@ all:
SELECT (select COUNT( _from ) from wiretaps group by _from) as num_kills,
(select COUNT( _to ) from wiretaps group by _to) as num_deaths,
_from as name
FROM wiretaps
WHERE message LIKE "%PvP:%"
http://sqlfiddle.com/#!2/1e5d9/1
| _FROM | _TO | MESSAGE | ID |
---------------------------------
| naez | salty | PvP: | 1 |
| naez | prince | PvP: | 2 |
| chuck | naez | PvP: | 3 |
預期產量:
| name | num_kills | num_deaths |
---------------------------------
| naez | 2 | 1 |
| prince | 0 | 1 |
| chuck | 1 | 0 |
| salty | 0 | 1 |
select name, sum(num_kills) num_kills, sum(num_deaths) num_deaths
from (
select _from name, count(*) num_kills, 0 num_deaths
from wiretaps
where message like '%PvP:%'
group by _from
union all
select _to name, 0 num_kills, count(*) num_deaths
from wiretaps
where message like '%PvP:%'
group by _to) x
group by name
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.