2016-09-06 98 views
-3

爲什麼沒有從下面的代碼返回數據?

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

也許是因爲沒有數據返回?提供您正在查詢的內容的樣本。 – Takarii

回答

-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)); 

這是一個糟糕的查詢。你應該使用distinct使用inner joinselect * from tabel a, tabel b, tabel c

:你必須(在不同的領域)添加組