透视Oracle查询

时间:2016-09-06 07:51:55

标签: java php android oracle sap

为什么以下代码没有返回数据?

SELECT *
FROM (SELECT p_code, short_name,qty_stock
      FROM sample_new.daily_stock)
PIVOT (sum(qty_stock) AS sum_quantity FOR (short_name) IN 
      (SELECT DISTINCT short_name FROM sample_new.daily_stock));

1 个答案:

答案 0 :(得分:-1)

select * from (select p_code,short_name,qty_stock from
sample_new.daily_stock) pivot (sum(qty_stock) as sum_quantity for
(short_name) in (select distinct short_name from
sample_new.daily_stock));

这是一个糟糕的查询。您应该使用inner joinselect * from tabel a, tabel b, tabel c

使用distinct:您必须添加分组依据(不同的字段)