MySQL 获取具有不同值的数据集
我有一个简单的问题;我认为会有一个简单的解决方案。想象一个这样的表:
Name Timestamp Data
Bob 2011-01-01 01:00:00 Hi
Alice 2011-02-02 02:00:00 Hello
Alice 2011-03-03 03:00:00 Hello
Bob 2011-04-04 04:00:00 Bye
Charlie 2011-05-05 05:00:00 Cheese
Charlie 2011-06-06 06:00:00 Toast
我想要的只是能够运行一个查询来显示每个名称的最新条目。因此,对于上表,我想要这样的输出:
Name Timestamp Data
Bob 2011-04-04 04:00:00 Bye
Alice 2011-03-03 03:00:00 Hello
Charlie 2011-06-06 06:00:00 Toast
按数据排序。我不知道该怎么做。我以为我可以这样做:
SELECT DISTINCT(Name), timestamp, Data FROM Table ORDER BY Data
但这不起作用。任何帮助将不胜感激, 干杯。
I have a simple problem; one which I thought would have a simple solution. Imagine a Table like this:
Name Timestamp Data
Bob 2011-01-01 01:00:00 Hi
Alice 2011-02-02 02:00:00 Hello
Alice 2011-03-03 03:00:00 Hello
Bob 2011-04-04 04:00:00 Bye
Charlie 2011-05-05 05:00:00 Cheese
Charlie 2011-06-06 06:00:00 Toast
All I want is to be able to run a query that shows the most recent entry for each Name. So with the above table, I would like an output like this:
Name Timestamp Data
Bob 2011-04-04 04:00:00 Bye
Alice 2011-03-03 03:00:00 Hello
Charlie 2011-06-06 06:00:00 Toast
Ordered by Data. I can't figure out how to do this. I though I could just do:
SELECT DISTINCT(Name), timestamp, Data FROM Table ORDER BY Data
But this doesn't work. Any help would be most appreciated,
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用此查询获取最后的唯一值,
Use this query to get last unique values,