Cách Pivot kết quả ...
 
Notifications
Clear all

Cách Pivot kết quả truy vấn trong SAP HANA

1 Posts
1 Users
0 Likes
405 Views
admin
Posts: 337
Admin
Topic starter
(@admin)
Prominent Member
Joined: 3 years ago

Yêu cầu: 

[img] [/img]

Tình huống biết trước các giá trị cố định để chuyển từ hàng dọc sang hàng ngang, ta sử dụng hàm Case để xử lý như sau:

select
 Product,
 case when Variant = 'Blue' then Quantity else NULL end as "Blue",
 case when Variant = 'Red' then Quantity else NULL end as "Red",
 case when Variant = 'White' then Quantity else NULL end as "White"
from Orders;

Kết quả 1:

[img] [/img]

Trường hợp muốn tổng hợp Quantity theo variant, ta sử dụng Case và kết hợp hàm Sum để xử lý:

[img] [/img]

 

Reply
Share:
x  Powerful Protection for WordPress, from Shield Security
This Site Is Protected By
Shield Security