gpt4 book ai didi

mysql - 选择具有特定值的行之后的行

转载 作者:可可西里 更新时间:2023-11-01 07:33:39 25 4
gpt4 key购买 nike

嘿,我仍然对查询和其他东西很感兴趣,所以请原谅所有常见的 sql 问题 8)

无论如何,我正在尝试选择某个值之后的行。不明白?好的,这就是它的实际外观。

表:消息

+------------+-----------+---------+-------+---------------------------------------+----------------+------------------+
| message_id | thread_id | user_id | to_id | body | message_status | uid_sent_deleted |
+------------+-----------+---------+-------+---------------------------------------+----------------+------------------+
| 1 | 1 | 1 | 7 | How are you bro? | read | 1 |
| 2 | 1 | 7 | 1 | IM good what about you kenny? | read | 0 |
| 3 | 1 | 1 | 7 | Same just chilling how is your sister | read | 1 |
| 4 | 1 | 7 | 1 | Shes coool u know just doin great | read | 0 |
| 7 | 1 | 1 | 7 | Thats nice | read | 1 |
| 8 | 1 | 7 | 1 | Yupp | read | 0 |
| 9 | 1 | 1 | 7 | hhahaha | read | 1 |
| 10 | 1 | 7 | 1 | anyways.... | unread | 0 |
+------------+-----------+---------+-------+---------------------------------------+----------------+------------------+

如果消息 ID 为 9,则 uid_sent_deleted 列中的值为“1”。我正在尝试选择 uid_sent_deleted 列中最后一行值为“1”之后的行。

这是我目前正在使用的 sql。感谢您的帮助!!

SELECT message_id, thread_id, messages.user_id, to_id, body, message_status, uid_sent_deleted
FROM messages
INNER JOIN messages_thread ON messages_thread.id = messages.thread_id
WHERE thread_id =1
GROUP BY messages.message_id
ORDER BY message_id ASC

最佳答案

... WHERE thread_id = 1 AND id > 
(SELECT MAX(id) FROM messages WHERE uid_sent_deleted = 1)

关于mysql - 选择具有特定值的行之后的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5126116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com