0
(
SELECT * 
FROM (

SELECT d
FROM myTable
WHERE id =  "4h"
AND d <  "2011-12-08 12:00:00"
ORDER BY d DESC 
LIMIT 10
)tmp
ORDER BY d ASC
)
UNION (

SELECT d
FROM myTable
WHERE id =  "4h"
AND d >=  "2011-12-08 12:00:00"
ORDER BY d ASC 
LIMIT 10
)

2 つのSELECTステートメントとUNION. 最初に 10 個の先行を取得するためにSELECT使用し、次にそれを 1 秒でエンベロープしてすべての結果を順番に取得しようとしましたが、何らかの理由で機能しません。ORDER BY DESCORDER BY ASCASC

これが私が現在得ている結果です:

d
2011-12-08 08:00:00
2011-12-08 04:00:00
2011-12-08 00:00:00
2011-12-07 20:00:00
2011-12-07 16:00:00
2011-12-07 12:00:00
2011-12-07 08:00:00
2011-12-07 04:00:00
2011-12-07 00:00:00
2011-12-06 20:00:00 <- These top 10 results should ASC!
2011-12-08 12:00:00
2011-12-08 16:00:00
2011-12-08 20:00:00
2011-12-09 00:00:00
2011-12-09 04:00:00
2011-12-09 08:00:00
2011-12-09 12:00:00
2011-12-09 16:00:00
2011-12-09 20:00:00
2011-12-11 20:00:00

そして、ここに私が欲しいものがあります:

d
2011-12-06 20:00:00
2011-12-07 00:00:00
2011-12-07 04:00:00
2011-12-07 08:00:00
2011-12-07 12:00:00
2011-12-07 16:00:00
2011-12-07 20:00:00
2011-12-08 00:00:00
2011-12-08 04:00:00
2011-12-08 08:00:00
2011-12-08 12:00:00
2011-12-08 16:00:00
2011-12-08 20:00:00
2011-12-09 00:00:00
2011-12-09 04:00:00
2011-12-09 08:00:00
2011-12-09 12:00:00
2011-12-09 16:00:00
2011-12-09 20:00:00
2011-12-11 20:00:00
4

1 に答える 1

2
(
  SELECT   d
  FROM     myTable
  WHERE    id = '4h' AND d <  '2011-12-08 12:00:00'
  ORDER BY d DESC
  LIMIT    10
) UNION ALL (  
  SELECT   d
  FROM     myTable
  WHERE    id = '4h' AND d >= '2011-12-08 12:00:00'
  ORDER BY d ASC
  LIMIT    10
)
ORDER BY d ASC
于 2012-09-04T21:20:55.240 に答える