我下面查詢獲取記錄從表penilaian_header
& penilaian_detail
查詢顯示錯誤結果
select *
from
(
select
row, a.tanggal,b.OutletCode,c.Nilai,a.Nip,b.Fullname,a.KodePenilaian,
f.Description as posisilama, d.ShortDesc as posisibaru
from penilaian_header a
left join Employee b on a.Nip = b.Nip
left join Position f on b.PositionCode = f.PositionCode
left join Position d on a.PositionCode = d.PositionCode
left join Penilaian_Detail e on a.KodePenilaian = e.KodePenilaianH
left join arealeader g on g.OutletCode = b.OutletCode
left join (
select
ROW_NUMBER() OVER(PARTITION BY KodePenilaianH ORDER BY idPenilaiand DESC) AS Row,
Nilai,
KodePenilaianH
from penilaian_Detail
) c on a.KodePenilaian = e.KodePenilaianH
where a.Outlet like '%%' and Periode like '%%'
) nilai
pivot
(
sum(nilai) for row in ([1],[2],[3],[4],[5])
) piv;
記錄我的紀錄penilaian_detail
結果應該與penilaian_detail
相同。請告訴我如何解決它。
http://sqlfiddle.com/#!3/f7e4d/8
感謝@dhruvjoshi的說明。現在的結果是像什麼,我預計
首先,我刪除此 left join Penilaian_Detail e on a.KodePenilaian = e.KodePenilaianH
然後我在結果改變這種 on a.KodePenilaian = e.KodePenilaianH
到on a.KodePenilaian = c.KodePenilaianH
我從來沒有使用sqlfiddle。但我嘗試一下,這裏是我的鏈接http://sqlfiddle.com/#!3/1ec6e/1 – Boby
你還需要在表中插入一些數據來評估查詢 – DhruvJoshi
我已經插入了一些http:// sqlfiddle.com/#!3/f7e4d/8 – Boby