我有數據庫如下:如何使用SELECT DISTINCT
npw | sales_name | sales_type | Region |
-----------------------------------------
1 | Rob | private 1 | 1 |
2 | Cait | private 2 | 2 |
3 | Blue | public | 4 |
4 | ReD | public | 3 |
5 | Max | private 1 | 2 |
,我想使它看起來像:
region| private 1 | private 2 | public |
-----------------------------------------------
1 | - | - | - |
2 | - | - | - |
3 | - | - | - |
4 | - | - | - |
,所以我想不同的地區列作爲行和不同的sales_type列作爲列標題。將來可能會增加新的sales_type。 什麼SQL查詢&使新的sales_type自動添加到新的列標題?
選擇一個數據庫請 – e4c5
哪個RDBMS你實現這樣的結果正在使用 ? mysql,sql-server,oracle?相應地標記問題。 –
根據數據,多少個sales_type只能有3個? –