我正在尝试运行此SQL查询:
SELECT * from tickets
where status = 'Completed'
and DATE(closed_timestamp) = '2014-04-25'
group by assigned_to
我想显示状态为“已完成”的行数最多的assigned_to
列以及今天closed_timestamp
日期
如何确保它显示最多行的assigned_to
?
答案 0 :(得分:4)
假设“今天”是问题中的日期,这是你想要的吗?
SELECT assigned_to
from tickets
where status = 'Completed' and DATE(closed_timestamp) = '2014-04-25'
group by assigned_to
order by count(*) desc
limit 1;
答案 1 :(得分:0)
Select Count (whatever your primary key column is) as number
from tickets where status = 'Completed' and DATE(closed_timestamp) = '2014-04-25'
group by assigned_to
order by number desc
LIMIT 1;
这将计算具有相同assigned_to值的ID数量,并将其限制为第一个结果。
答案 2 :(得分:0)
这样的事情:
select assigned_to, count(*) records
from etc
group by assign_to
order by records desc
limit 1