gpt4 book ai didi

php - 基于计数的限制

转载 作者:行者123 更新时间:2023-11-29 01:33:21 24 4
gpt4 key购买 nike

我对类别和内容使用一个表格。

pid 字段中 Categories 的值为 0。

例如:

示例表

--------------------------
id | pid | name
--------------------------
1 | 0 | Some catgory 1
--------------------------
2 | 1 | Some content of first category
--------------------------
3 | 1 | Other content of first cat
--------------------------
4 | 0 | Second category
--------------------------
5 | 0 | Category number 3
--------------------------
6 | 5 | Content of category 3
--------------------------
7 | 4 | Content of 2 cat
--------------------------
8 | 5 | Content of 3 cat
--------------------------
9 | 5 | Other Content of 3 cat
--------------------------
10 | 5 | One more content of 3 cat
--------------------------
11 | 4 | Content of 2 cat
--------------------------
12 | 5 | One more content of 3 cat
--------------------------
13 | 1 | First cat content
--------------------------
14 | 1 | Other content of 1 cat

如何在一次查询中获取所有类别和 10 个内容项?

最佳答案

要在单个查询中获取两个单独查询的结果,请使用 UNION ALL:

SELECT id, pid, name
FROM yourtable
WHERE pid = 0
UNION ALL
(
SELECT id, pid, name
FROM yourtable
WHERE pid <> 0
LIMIT 10
)

关于php - 基于计数的限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4699871/

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