id record_name record_value
-------------------------------------
1001 price1 12
1001 price2 1
1001 price3 8
1201 price1 18
1201 price2 2
1201 price3 6
1601 price1 12
1601 price2 8
1601 price3 8
id price1 value price2 value price3 value
--------------------------------------------------------------------------
1001 price1 12 price2 1 price3 8
1201 price1 18 price2 2 price3 6
我收到錯誤
子查詢返回多個值。當子查詢遵循=,!=,<,< =,>,> =或當子查詢用作表達式時,這是不允許的。
我用這個查詢:
select distinct
a.id, 'Price1',
(select record_value
from table_name
where id = a.id and record_name = 'price1') as 'value1',
'Price2',
(select record_value
from table_name
where id = a.id and record_name = 'price2') as 'value2',
'Price3',
(select record_value
from table_name
where id = a.id and record_name = 'price3') as 'value3'
from
table_name a
請儘量解決這個問題!
那麼,哪個DBMS? Postgres的? SQL Server? SQLite的? – 2014-11-25 07:30:01
好問題。哪一個 – Jaques 2014-11-25 07:31:30
隨着你在這裏發佈的數據..有沒有像這樣的錯誤..它的工作很好.. – Deepshikha 2014-11-25 07:36:56