I have value like this.

我有这样的价值。

id  website   time
1   aaa.com   11.10
2   bbb.com   11.10
3   ccc.com   11.10
4   aaa.com   11.11
5   bbb.com   11.11
6   ccc.com   11.11

I want to select latest and not same data in table. It should be .

我想在表格中选择最新的而不是相同的数据。它应该是 。

4   aaa.com   11.11
5   bbb.com   11.11
6   ccc.com   11.11

I query like this

我这样查询

"SELECT * FROM name GROUP BY website ORDER BY id DESC";

It alway show DESC and ASC.

它总是显示DESC和ASC。

1   aaa.com   11.10
2   bbb.com   11.10
3   ccc.com   11.10

How to select latest value with not same data ?

如何选择不同数据的最新值?

1 个解决方案

#1


2

Join to a subquery which finds the latest record for each website:

加入子查询,查找每个网站的最新记录:

SELECT t1.*
FROM yourTable t1
INNER JOIN
(
    SELECT website, MAX(time) AS max_time
    FROM yourTable
    GROUP BY website
) t2
    ON t1.website = t2.website AND
       t1.time = t2.max_time;

You are storing your times apparently in some text format. This isn't desirable, and it would be better to store date times instead. If the width of the time is always the same (5 telling from your sample data), then my query should work though.

您显然以某种文本格式存储您的时间。这是不可取的,而且最好存储日期时间。如果时间的宽度总是相同的(从样本数据中得知),那么我的查询应该可行。

更多相关文章

  1. PHPExcel导入导出及大量数据导入缓存方式的修改
  2. php-fpm通过request_slowlog_timeout检查哪个脚本执行时间长
  3. 无法从Ajax POST请求中将带空格的数据导入数据库
  4. php时间函数——获取过去24小时内每个小时的节点
  5. 将纪元时间转换为日期PHP
  6. php写app接口并返回json数据
  7. MySQL错误1046:未选择数据库
  8. 社交登录实现的数据库结构?
  9. Json调用JSON.parse:意外结束数据

随机推荐

  1. android 显示系统 surfaceflinger 分析
  2. 基于树莓派的 Android(安卓)Things 开发
  3. android关于百度地图显示网格问题
  4. Android系列之网络(二)----获取HTTP请求头
  5. Android运行机制
  6. Mars Android视频教程完整版高清在线观看
  7. Android进阶-Android系统信息与安全机制
  8. ProgressBar(进度条) 分类 Android 基础
  9. Android 属性总结
  10. android 中文 api (64) ―― Scroller