我需要帮助,我有 mysql 表: 我的 controller: 现在的问题是当我看到结果时,它给了我例如 但我想数... 请有人帮我谢谢?? ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我有一个事件表,其中包含太多列。 我想查询3列,DateTimeResolved,团队和个人。 首先,我想将DateTimeResolved列中的时间与日期分开。 然后我想知道自2017年4月以来,每个团队有多少个人(唯一身份)解决了事件。
能做到吗?
我有以下查询工作,但显然它们需要调整,因为它们没有给我我想要的最终结果。
select stat_datetimeresolved, resolvedbyteam, resolvedby
from [dbo].[Incident]
where Stat_DateTimeResolved is not null
and Stat_DateTimeResolved >= '2017-04-01 00:00:00'
order by Stat_DateTimeResolved asc
select CAST(stat_datetimeresolved as date),
COUNT(resolvedby)
from [dbo].[Incident]
group by CAST(Stat_DateTimeResolved as DATE)
order by CAST(stat_datetimeresolved as DATE) asc
你很亲密 您可以将DISTINCT关键字添加到COUNT中,以按天获取唯一身份的团队成员数。
SELECT CAST(stat_datetimeresolved as date) as DateResolved
, ResolvedByTeam
, COUNT(DISTINCT resolvedby) as ResolvedByCnt
FROM [dbo].[Incident]
WHERE Stat_DateTimeResolved >= '20170401'
GROUP BY CAST(Stat_DateTimeResolved as DATE), ResolvedByTeam
ORDER BY CAST(stat_datetimeresolved as DATE) asc, ResolvedByTeam
您在此处的问题中有多个不兼容的请求。 我认为您所追求的实际上是:
为此,您只需要返回一个唯一的列表,其中包含解决日期,个人所属的团队以及实际做出解决的团队,然后进行汇总:
with r as
(
select distinct cast(stat_datetimeresolved as date) as DateResolved
,ResolvedByTeam
,ResolvedBy
from [dbo].[Incident]
where Stat_DateTimeResolved >= '20170401' -- NULL check is redundant if you are filtering for a value
)
select DateResolved
,ResolvedByTeam
,count(ResolvedBy) as NumIndividualsMakingResolutions
from r
group by DateResolved
,ResolvedByTeam
order by DateResolved
,ResolvedByTeam;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.