我有一个包含account_id和creation_date列的表。creation_date在创建帐户时获得当前时间戳(插入行)-如何返回最早的帐户?换句话说,表中具有最早时间戳的行?我试过SELECT account_id, MIN(creation_date) FROM table,但似乎不能让MIN()按照我希望的方式工作。
account_id
creation_date
SELECT account_id, MIN(creation_date) FROM table
MIN()
ecbunoof1#
你就不能:
select t.account_id from t order by creation_date fetch first 1 row only;
xnifntxz2#
您可以使用ORDER BY子句对结果进行排序,然后使用LIMIT子句选取第一条记录:
ORDER BY
LIMIT
SELECT * FROM table ORDER BY creation_date LIMIT 1
u0sqgete3#
看起来这是个办法:SELECT account_id, creation_date FROM table WHERE creation_date = (SELECT MIN(creation_date) FROM table)
SELECT account_id, creation_date FROM table WHERE creation_date = (SELECT MIN(creation_date) FROM table)
3条答案
按热度按时间ecbunoof1#
你就不能:
xnifntxz2#
您可以使用
ORDER BY
子句对结果进行排序,然后使用LIMIT
子句选取第一条记录:u0sqgete3#
看起来这是个办法:
SELECT account_id, creation_date FROM table WHERE creation_date = (SELECT MIN(creation_date) FROM table)