2
誰能幫我組2臺,並顯示如下圖所示...如何在MySQL中通過pivot來使用group?
我的第一個表是:
user_id | department ----------------------- 1 | user1 ---------------------- 2 | user2 ----------------------
和表2是:
reserve_id | user_id | reserve_status -------------------------------------- 1 | 1 | 1 -------------------------------------- 2 | 1 | 1 -------------------------------------- 3 | 1 | 2 -------------------------------------- 4 | 2 | 2 -------------------------------------- 5 | 2 | 0 -------------------------------------- 6 | 2 | 1 *reserve_status 0 uncheck, 1 = approve , 2 = disapproval
我想要的產品這樣的:
department | sumreserve | sumreservapprove | sumreserveunapprove | uncheck ---------------------------------------------------------------------------- user1 | 3 | 2 | 1 | 0 ---------------------------------------------------------------------------- user2 | 3 | 1 | 1 | 1
對不起英語差
謝謝你的回答,你讓我的一天^ ^。 – Manioz