SQL Select使值仅出现一次 [英] SQL Select to make a value appear only once
问题描述
对于那些一直在使用此Twitter克隆帮助我的人,谢谢!!在您的帮助下,我已成功完成了大部分工作,现在终于进入了追随者职能的最后一步.
For those that have been helping me along the way with this twitter-clone, thank you!! With your help, I've managed to get most things working and finally now to the last steps of the followers function.
现在,我有一个包含以下字段的数据集:用户名,tweet,日期
Right now, I have a dataset with the following fields: username, tweet, date
数据示例如下:
Username Tweet Date
kenny hi! 2011-10-07 19:07:00
stan hello 2011-10-05 18:07:00
kenny looks like rain 2011-10-05 17:07:00
stan hello 2011-10-05 14:07:00
cartman authoritay! 2010-10-05 14:07:00
我一直在努力处理SQL语句,该语句将生成一个数据集,其中每个用户在其最新推文中仅出现一次.因此,基于以上内容,看起来像这样:
And I've been wrestling with the SQL statement that would produce a data set in which each user appears only once with their latest tweet. So, based on the above, something that looks like this:
Username Tweet Date
kenny hi! 2011-10-07 19:07:00
stan hello 2011-10-05 18:07:00
cartman authoritay! 2010-10-05 14:07:00
我一直在搜索sql搜索,并尝试了COUNT,DISTINCT,MAX的变体,但无济于事.任何帮助将不胜感激!谢谢!
I've been googling sql searches and have tried variations of COUNT, DISTINCT, MAX, but to no avail. Any help would be greatly appreciated! Thank you!
推荐答案
select d1.username, d1.tweet, d1.date from data d1 where d1.date =
(select max(d2.date) from data d2 where d1.username = d2.username)
这篇关于SQL Select使值仅出现一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!