mysql - 如何使用 Jetbrains Exposed 库通过左连接添加单行?
问题描述
我需要在单个查询中获取所有聊天以及最新的聊天消息。
我有一个 SQL 查询:
SELECT * FROM chats
// here I obtain latest message uid for chat
LEFT OUTER
JOIN ( SELECT
chat_uid,
MAX(timestamp) AS last_message_ts
FROM chat_messages
GROUP BY chat_messages.chat_uid) AS subq
ON subq.chat_uid = chats.chat_uid
// here I obtain latest message for chat
LEFT OUTER
JOIN chat_messages AS msgs
ON msgs.chat_uid = subq.chat_uid
AND msgs.timestamp = subq.last_message_ts
但现在我想把它转换成Exposed Kotlin
代码。
而且我不知道如何在这里使用多个左外连接。有什么想法吗?
解决方案
推荐阅读
- r - 如何使用 kable 和 map 将多个表保存为图像?
- visual-studio-code - 我在 ubuntu 中有错误,我使用“xmodmap”禁用“Pg Up”和“Pg Dn”键功能。但是在 vscode 中“xmodmap”不起作用
- floating-point - 如何将浮点变量转换为字符串?
- java - 应该添加什么来计算和输出每个行为的变量 Energy 的增加或减少?
- c# - 如果条件为假,它也正在重定向到注册页面,任何人都可以在这方面提供帮助
- reactjs - React MUI V5 AppBar背景颜色不变
- python - 正则表达式:摆脱连续的标点符号
- android - 他们是否有任何方式将 Google Play 计费添加到 Python 项目中?
- windows - Windows 更新安装在 Amazon SSM 日志中,但在更新历史记录中检查时失败
- python - 无法在 Mac M1 上安装 TensorFlow。安装过程中遇到错误