1より大きいカウントのカウントテーブルを合計したい次のクエリがあります。これを行う方法が正確にわかりません。
SELECT count(id) as count,
id,
location_id,
time,
weekofyear(time)
from table where weekofyear(time) = '28'
group by location_id, id
having count > 1
order by count desc
結果:
count id location_id time weekofyear(time)
5 32265 409 7/12/14 3:58 28
5 32266 409 7/12/14 3:59 28
5 27532 399 7/12/14 4:54 28
4 31124 41 7/7/14 4:41 28
だから私は合計が19を示すことを望みます
独自のクエリからの単純な副選択でそれを行う必要があります。
SELECT
SUM(t.count)
FROM (
SELECT count(id) as count,
id,
location_id,
time,
weekofyear(time)
from table where weekofyear(time) = '28'
group by location_id, id
having count > 1
) as t
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加