gpt4 book ai didi

mysql - 限制专精

转载 作者:行者123 更新时间:2023-11-30 23:27:19 25 4
gpt4 key购买 nike

SELECT *, IFNULL(parent, id) AS p, IFNULL(reply_comment_id, id) AS r
FROM article_comments ORDER BY p ASC, r ASC, date DESC

enter image description here

我想使用 LIMIT。如果我有更多行,我想用“p”限制查询。在图像中: ("p": 1, 1, 1, 1, 1) – 这是一个,("p": 2, 2, 2, 2, 2, 2, 2) – 这是两个...

例如,我想:如果我使用 LIMIT 1,则只显示 ("p": 1, 1, 1, 1, 1)。 enter image description here

最佳答案

这是我要使用的查询:

SELECT * FROM
FROM article_comments
WHERE id = 1 OR parent = 1
ORDER BY parent ASC, reply_comment_id ASC, `date` DESC

请注意,我认为此处不需要您的计算列。当按父级和 reply_comment_id 升序排序时,NULL 值将排在第一位。

确保您在 parent、reply_comment_id 和日期字段上有索引(除了 id,我认为它是主键)

此外,您可能需要考虑为日期列使用日期时间字段,而不是 unix 时间戳。在查看数据库中的数据以及尝试查询日期范围时,它对用户非常友好/因此可以像这样编写过滤器:

WHERE `date` BETWEEN '2012-01-01 00:00:00' AND '2012-12-31 23:59:59'

不必进行时间戳转换。

关于mysql - 限制专精,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12610388/

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