私の選択クエリ:クロスタブSQL Serverクエリ
SELECT
COUNT(*) * 500 AS TotalFee,
ISNULL(Employee.EFName, '') + ' ' + ISNULL(Employee.EMName, '') + ' ' + ISNULL(Employee.ELName, '') as Name,
CAST(MONTH(sdatetime) AS int) as Months
FROM
Patient_Services
INNER JOIN
Employee ON Patient_Services.Doctor_ID = Employee.EmpID
WHERE
(Patient_Services.S_ID = 1606)
AND CAST(MONTH(sdatetime) AS INT) BETWEEN 1 AND 6
GROUP BY
CAST(MONTH(sdatetime) AS INT), Employee.EFName, Employee.EMName, Employee.ELName
ORDER BY
CAST(MONTH(Patient_Services.sdatetime) AS INT)
結果
TotalFee | Name | Months
38000 | AKIF DILSHAD | 1
1500 | MATEEN AKRAM | 1
1500 | AKIF DILSHAD | 2
2200 | AKIF DILSHAD | 3
1500 | NASERA BHATTI | 4
500 | NASERA BHATTI | 5
500 | NASERA BHATTI | 6
12000 | AKIF DILSHAD | 6
私の望む結果:
Name |Jan |Feb |Mar |Apr |May |June |Total |60% |40%
AKIF DILSHAD |38000 |1500 |2200 |0 |0 |12000 |53700 |32220 |21480
MATEEN AKRAM |1500 |0 |0 |0 |0 |0 |1500 |900 |600
NASERA BHATTI |0 |0 |0 |1500 |500 |500 |2500 |1500 |1000
私の望ましい結果を得るために、私のクエリを変換するのに役立ちます。
はあなたにも名前でグループ化することではないでしょうか? –
[ピボット](http://stackoverflow.com/questions/15931607/convert-rows-to-columns-using-pivot-in-sql-server)を使用してください。 – NEER
'MONTH()'関数**はすでに* * 'INT'を返します。明示的に' INT'にキャストする理由と意味は全くありません。 –