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));
答案 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 join
或select * from tabel a, tabel b, tabel c
使用distinct
:您必须添加分组依据(不同的字段)