-2

我在 mysql 中有一个包含很多字段的表

我需要一个查询来返回(以相同的原始格式!)最后 3 个日期(日期之间可能有很大的差距)

IE:

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

ETC...

任何帮助将不胜感激

我必须让他们在同一排!

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

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)
4

3 回答 3

2

编辑 :

SELECT group_concat(date) FROM (SELECT date FROM my_table ORDER BY date DESC LIMIT 3) AS temp
于 2012-04-18T10:09:54.250 回答
2

更正-

 SELECT group_concat(date) FROM ( select date from table_name order by date desc limit 3) as a
于 2012-04-18T10:18:35.010 回答
1
SELECT GROUP_CONCAT(a.date ) 
FROM (
SELECT date
FROM my_table
ORDER BY date DESC 
LIMIT 3
) AS a
于 2012-04-18T10:32:44.900 回答