相当基本,但我现在卡住了。
在Informix数据库(无枢轴选项)上,我正在搜索使用SQL转换下表的动态方法:
book | info | value ----------------------------- Moby Dick | price | high Moby Dick | stock | few Hamlet | price | low Hamlet | stock | many Faust | price | medium Faust | stock | normal
结果表:
book | price | stock ----------------------------- Moby Dick | high | few Hamlet | low | many Faust | medium | normal
感谢您的帮助!
答案 0 :(得分:2)
您可以根据按照书籍分组的CASE
表达式进行汇总。尝试这样的事情。
SELECT book,
MAX(CASE WHEN info = 'price' THEN value END) as price,
MAX(CASE WHEN info = 'stock' THEN value END) as stock
FROM table1
GROUP BY book