按时间戳查询订单

时间:2020-05-14 09:43:52

标签: postgresql sql-order-by

尝试按timestamptz列“已发送”(最早显示在页面的最前)对查询结果进行排序。我已经尝试过按发送的ASC和DESC排序,但这似乎使它们恢复了相同(不正确)的顺序。

这是查询-

SELECT messages.bootcamper_id, first_name,
    surname,
    photo_url,
    message,
    sent
FROM messages  
  LEFT JOIN bootcampers ON messages.bootcamper_id = bootcampers.bootcamper_id 
ORDER BY sent DESC 
LIMIT 30;

这是该表的创建表脚本:

CREATE TABLE IF NOT EXISTS messages (
  message_id SERIAL PRIMARY KEY, 
  sent timestamptz NOT NULL DEFAULT now(), 
  bootcamper_id INTEGER REFERENCES bootcampers(bootcamper_id), 
  message TEXT
)

这是pgadmin中表的屏幕截图

enter image description here

0 个答案:

没有答案