Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设如下表,是否可以轻松查询最近添加到表中的项目?
create table messages( person_uuid uuid, uuid timeuuid, message text);
此表的主要目的是保存发送给特定用户的消息列表,但还需要显示所有最近用户的 RSS 提要,例如:
select person_uuid, message from messages order by uuid limit 30;
您需要使用复合主键才能按日期排序。
CREATE TABLE messages( person_uuid uuid, date timeuuid, message text, PRIMARY KEY(person_uuid,date) );
然后你可以做
SELECT * FROM messages WHERE person_uuid=xxx ORDER BY date DESC LIMIT 20;