如何编写 T-SQLhaving 查询?
我正在使用 SSMS 2008,并尝试编写一个 TSQL 语句来仅返回每个“people_id”具有多个“intake_dt”值的记录。但下面这个查询似乎不起作用。我该如何重写这个?
SELECT el.people_id, el.actual_date
INTO #READMISSIONS
from event_log_rv el
join enrollment_view en on en.event_log_id = el.event_log_id
join (select actual_date from event_log_rv where actual_date is not null group by actual_date having count(*) > 1) t on t.actual_date = el.actual_date
where el.actual_date is not null
group by el.people_id, el.actual_date
我没有收到任何错误,但输出不只显示一条记录/人。我想要的只是每人一条具有最新实际日期的记录。
I am using SSMS 2008 and am trying to write a TSQL statement to return only records with multiple "intake_dt" values per "people_id". But this query below doesn't seem to be working. How do I rewrite this?
SELECT el.people_id, el.actual_date
INTO #READMISSIONS
from event_log_rv el
join enrollment_view en on en.event_log_id = el.event_log_id
join (select actual_date from event_log_rv where actual_date is not null group by actual_date having count(*) > 1) t on t.actual_date = el.actual_date
where el.actual_date is not null
group by el.people_id, el.actual_date
I am not getting any errors, but the output is not displaying just one record / person. All I want is one record per person with the latest actual_date.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这会给你你想要的结果吗?
Does this give you the result you want?