我有一个如下表所示的MySQL表:
++++++++++++++++++++++++++++++
id | uid | key | value
++++++++++++++++++++++++++++++
1 | u01 | instrument | guitar
2 | u01 | level_____ | 10
3 | u02 | instrument | guitar
4 | u02 | level_____ | 1
现在我想执行搜索以查找: 所有UID都可以兼用吉他,等级为10 结果应显示为:
结果>
uid : u01
但我有点卡住了,不知道应该是什么样的查询。 我知道我可能必须执行条件聚合,但可以请某人指导我
答案 0 :(得分:0)
SELECT DISTINCT UID FROM TABLE WHERE VALUE IN ('PIANO', 'VIOLIN')
答案 1 :(得分:0)
select uid
from your_table
where `key` = 'instrument'
and `value` in ('guitar','violin')
group by uid
having count(distinct `value`) = 2