SQL选择从表中的最后3日期

我有一个表,有很多领域在MySQL

我需要一个查询返回(在相同原料!)前最后3日期(日期可以让他们之间较大的差距)

即:

2012/01/20 2012/01/18 2012/01/12 2012/01/10 2012/01/04

等等...

任何帮助将不胜感激

我必须让他们在同一行中!

这是我尝试没有成功使用查询:

SELECT a.id, a.thedate, b.id AS id1, b.thedate AS thedate1, c.id AS id2, c.thedate as thedate2 FROM mytable AS a INNER JOIN mytable AS b ON a.id = b.id INNER JOIN mytable AS c ON b.id=c.id WHERE c.thedate = SELECT MAX(thedate)

--------------解决方案-------------

编辑:

SELECT group_concat(date) FROM (SELECT date FROM my_table ORDER BY date DESC LIMIT 3) AS temp

Corrected-

SELECT group_concat(date) FROM ( select date from table_name order by date desc limit 3) as a

SELECT GROUP_CONCAT(a.date )
FROM (
SELECT date
FROM my_table
ORDER BY date DESC
LIMIT 3
) AS a

分类:MySQL的 时间:2015-03-15 人气:1
本文关键词: MySQL和SQL
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.427 (s). 10 q(s)