我有这个查询:

select key, propkey, propvalue
from openidm.managedobjectproperties
where key in (
    select key
    from openidm.managedobjectproperties
    where propvalue in ('97539510','97939103'))
and propkey in ('/CRSMID','/partyID');


基本上返回以下输出:

key     | propkey  | propvalue
------------------------------
1482195 | /CRSMID  | 814427
1482195 | /partyID | 97539510
1488492 | /CRSMID  | 1415615
1488492 | /partyID | 97939103


对于每个键-都是相同的-我想以这种方式输出带有属性值的两列表(第一列为/ CRSMID,第二列为/ partyID):

CRSMID  | partyID
-------------------
814427  | 97539510
1415615 | 97939103


但是我不确定,因为按组分组不起作用。

最佳答案

使用条件聚合

select max(case when propkey='/CRSMID' then  propvalue end) CRSMID,
max(case when propkey='/partyID' then  propvalue end) partyID
from openidm.managedobjectproperties
where key in (
    select key
    from openidm.managedobjectproperties
    where propvalue in ('97539510','97939103'))
and propkey in ('/CRSMID','/partyID') group by key

关于mysql - MySQL输出从双行到按键分组的单个原始,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56867960/

10-16 14:19