gpt4 book ai didi

mysql - 如何为每个唯一用户 ID 提取两行

转载 作者:行者123 更新时间:2023-11-29 03:39:27 25 4
gpt4 key购买 nike

以下查询用于提取以下列和行。

问题是我无法从每个用户 ID 中提取两行。如果我使用限制,则只获取第一两行。

那么我如何为每个唯一用户 ID 提取两行。

例如:

two rows of userid 222
two rows of userid 122
two rows of userid 367

等等

文本操作:

预期输出:

最佳答案

假设 id 是您的用户 ID,post_ID 是唯一的。

(SELECT id,name,post,Image,post
FROM users
GROUP BY id
ORDER BY id
)
UNION
(SELECT id,name,post,Image,post
FROM users
WHERE post_ID NOT IN
(SELECT post_ID
FROM users
GROUP BY id
ORDER BY id)
GROUP BY id
ORDER BY id
)
ORDER BY id, post_ID

请检查我的查询,我从中得到以下答案:

(
SELECT store_id, `key_id` , `string` , `translate` , `locale`
FROM `core_translate` AS C
GROUP BY `store_id`
ORDER BY `store_id`
)
UNION (

SELECT store_id, `key_id` , `string` , `translate` , `locale`
FROM `core_translate` AS C
WHERE `key_id` NOT
IN (

SELECT `key_id`
FROM `core_translate` AS C
GROUP BY `store_id`
ORDER BY `store_id`
)
GROUP BY `store_id`
ORDER BY C.`store_id`
)
ORDER BY store_id, `key_id`

store_id    key_id  string  translate   locale
0 20 Screensize Screensize en_US
0 21 Gender Gender en_US
1 1 Size Size en_US
1 2 Color Color en_US
2 5 Large Image Large Image en_US
2 6 Medium Image Medium Image en_US
3 10 Manufacturer Manufacturer en_US
3 11 Dimensions Dimensions en_US
4 15 Description Description en_US
4 16 Weight Weight en_US

关于mysql - 如何为每个唯一用户 ID 提取两行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16208353/

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