这是我的查询:
SELECT v2.mac, v2.userag_hash, v2.area, count(*), count(distinct v2.video_id)
FROM video v2 JOIN (
SELECT distinct v.mac, v.userag_hash
from video v
WHERE v.date_pl >= '2012-01-30 00:00' AND
v.date_pl <= '2012-02-05 23:55'
ORDER BY rand() LIMIT 50
) table2
ON v2.mac = table2.mac AND
v2.userag_hash = table2.userag_hash AND
v2.date_pl >= '2012-01-30 00:00' AND
v2.date_pl <= '2012-02-05 23:55'
GROUP BY v2.mac, v2.userag_hash
我在数据库中有一个表“视频”,它包含几千个用户的数据,现在我想随机选择 50 个用户并根据选择的行计算,(每个用户由唯一的组合标识),这个查询的结果是:
usermac1, userag_hash1, area1, 10, 5
usermac2, userag_hash2, area2, 20, 8
...
但是如果我在查询末尾不使用“GROUP BY”,那么它只会返回一行:usermac, userag_hash, areax, 1500, 700(不知道这一行代表什么)
我想知道“1500, 700”是否是先前结果的最后两列的总和。比如 1500 = 10+20+... 700 = 5+8+...