我的查询如下:
D <- data.frame(A,B,C)
我想要这样的东西
SELECT
u.Title,
SUM(CASE datepart(month,VISIT_DATE) WHEN 1 THEN 1 ELSE 0 END) AS 'January',
SUM(CASE datepart(month,VISIT_DATE) WHEN 2 THEN 1 ELSE 0 END) AS 'February',
SUM(CASE datepart(month,VISIT_DATE) WHEN 3 THEN 1 ELSE 0 END) AS 'March',
SUM(CASE datepart(month,VISIT_DATE) WHEN 4 THEN 1 ELSE 0 END) AS 'April',
SUM(CASE datepart(month,VISIT_DATE) WHEN 5 THEN 1 ELSE 0 END) AS 'May',
SUM(CASE datepart(month,VISIT_DATE) WHEN 6 THEN 1 ELSE 0 END) AS 'June',
SUM(CASE datepart(month,VISIT_DATE) WHEN 7 THEN 1 ELSE 0 END) AS 'July',
SUM(CASE datepart(month,VISIT_DATE) WHEN 8 THEN 1 ELSE 0 END) AS 'August',
SUM(CASE datepart(month,VISIT_DATE) WHEN 9 THEN 1 ELSE 0 END) AS 'September',
SUM(CASE datepart(month,VISIT_DATE) WHEN 10 THEN 1 ELSE 0 END) AS 'October',
SUM(CASE datepart(month,VISIT_DATE) WHEN 11 THEN 1 ELSE 0 END) AS 'November',
SUM(CASE datepart(month,VISIT_DATE) WHEN 12 THEN 1 ELSE 0 END) AS 'December'
FROM
pidilite_feedback_app_dev_latest.dbo.visit v, pidilite_feedback_app_dev_latest.dbo.user_master u
WHERE
v.VISIT_DATE BETWEEN '2017-01-30 12:45:43.673' and '2017-05-24 12:45:43.673'
and u.ID = v.USER_ID
and v.VISIT_STATUS = 'submitted'
and u.delete_flag = 'F'
and v.delete_flag = 'F'
and v.DIVISION_CODE = '10'
GROUP BY v.USER_ID, u.Title
OR
SUM(CASE datepart(month,VISIT_DATE) WHEN 1 THEN 1 ELSE 0 END) AS concat(YEAR(VISIT_DATE),'January'),
但它不起作用,需要指导,谢谢