문제

I have a query that as the following rows:

Id     |      key          | Value 
1         Type.name.1        Value1 
2         Type.name.2        Value2
3         Type.desc.1        Desc1
4         Type.desc.2        Desc2

And I need a query that returns this:

Type.NameId  | Type.DescId
1              3
2              4

How can I do this in Postgres?

도움이 되었습니까?

해결책

SELECT *
FROM  (
   SELECT right(key, -10) AS name_id
   WHERE "value" ~~ 'Value%'
   ) n
FULL JOIN (
   SELECT right(key, -10) AS name_id, id AS desc_id
   WHERE "value" ~~ 'Desc%'
   ) d USING name_id;

Exact form depends on a lot of details missing in your question.

Your table design and naming convention give me the shivers.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top