gpt4 book ai didi

mysql - 选择查询两位数据

转载 作者:行者123 更新时间:2023-11-29 13:59:00 25 4
gpt4 key购买 nike

表(userData)如下所示:

userId    property    value
1 AGE 28
1 GENDER M
2 AGE 28
2 GENDER F
3 AGE 29
3 GENDER F
4 AGE 29
4 GENDER F

所以我想要得到类似的东西:

Gender    Age    Count
M 28 1
F 28 1
F 29 2

最佳答案

类似这样的吗?

SELECT
ud1.value AS gender,
ud2.value AS age,
COUNT(*) AS c
FROM userData ud1
JOIN userData ud2 ON
ud1.userId = ud2.userId AND
ud2.property = 'AGE'
WHERE ud1.property = 'GENDER'
GROUP BY gender, age

关于mysql - 选择查询两位数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15376071/

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