我有一个如下表格值,
id tank_id filledTime
1 TIND10 6PM,7PM,9PM,9PM,7PM,11PM,7PM,9PM,7PM,7PM,8PM,7PM,10PM,8PM,7PM,8PM,8PM,6PM,8PM,9PM,8PM,11PM,8PM
期待输出:
tank_id NoOfTimeFilledInSpecTime
TIND10 2(6PM),7(7PM),4(9PM),2(11PM),7(8PM),1(10PM)
注意:filledTime
是单列
如何使用mysql查询实现此目的?
答案 0 :(得分:0)
这选择了什么吗?
select tank_id, count(filledTime), filledTime
from yourtable
where filledTimein (select filledTimefrom yourtable)
and tank_id = 'TIND10'
group by tank_id,filledTime;
应输出:
tank_id |计数| filledtime TIND10 | 2 |下午6时
依旧......
答案 1 :(得分:0)
假设您的数据库是tankDetails并且表是tank。然后你可以得到一个类似的查询:
use tankDetails;
select tank_id,filledTime, count(filledTime) as NoofTime
from tank
group by tank_id,filledTime;
希望这有帮助!