2017-09-29 29 views
0

我在做MYSQL查詢。MYSQL配對添加號碼查詢

這是我的桌子。 enter image description here

我需要一個查詢結果包含增加計數值的行。

例如,如果我在找20000個計數值,結果列應是第三行,其中的日期是「2016年9月3日」((8576 + 8694 + 8689)> 20000)。

我的表模式有問題,但幫我查詢。

謝謝。

+0

你不應該至少按日期排序? –

+0

請在格式化文本(不是圖像)中共享樣本數據和所需輸出 – zarruq

回答

0

您正在尋找這樣的查詢,假設日期是唯一的:

select counter.* 
from counter 
inner join counter c2 
on counter.date >= c2.date 
and c2.searchword = 'cryptocurrentcy' 
where counter.searchword = 'cryptocurrency' 
group by counter.date 
having sum(c2.count) > 20000 
order by counter.date 
limit 1