分组子查询并使用concat_ws()分开并组合结果集
I have written query by combining two tables and result looks like below mentioned
Result Set
recipient_email | recipient_name | accrual_deadline | CCA |
---|---|---|---|
[email protected] | siva | jun 24 | [email protected] |
[email protected] | siva | jun 24 | [email protected] |
[email protected] | mohan | jun 24 | [email protected] |
[email protected] | mohan | jun 24 | [email protected] |
Query:
SELECT te.email AS recipient_email
,te.employee_name AS recipient_name
,(
SELECT CONVERT(VARCHAR, DATEADD(d, - 3, MAX(TRANSACTION_DATE)), 107)
FROM [POT].[vw_Calendar]
WHERE CURRENT_FISCAL_YEAR_FLAG = 'Y'
AND CURRENT_FISCAL_QUARTER_FLAG = 'Y'
) AS accrual_deadline
,'GR' AS emp_type
,te1.email AS CostCenterAnalyst FROM [POT].[vw_POT_Open_PO] op
LEFT JOIN POT.vw_Employee te ON te.Employee_Number = op.Goods_Recipient_Emp_ID
AND te.flag_Status = 'A'
JOIN POT.vw_Employee te1 ON te1.Employee_Number = op.pocostcenteranlystid
LEFT JOIN [POT].[tbl_POT_Open_PO_Accrual_Reminder_History] opair ON DATEPART(month, GETDATE()) + DATEPART(year, GETDATE()) = DATEPART(month, [Mail_Sent_On]) + DATEPART(year, [Mail_Sent_On])
AND [Recipient_Email] = te.email
AND opair.Flag_Active = 1
AND [Reminder_Type] = 'Accrual_Input'
WHERE te.email IS NOT NULL
AND opair.Recipient_Email IS NULL
AND te.Email IN (
'[email protected]'
,'[email protected]'
) GROUP BY te.email
,te.employee_name
,te1.email
I have to group the recipient_email and result should display like below
recipient_email | recipient_name | accrual_deadline | CCA |
---|---|---|---|
[email protected] | siva | jun 24 | [email  prectioned] ; [email protected] |
[email protected] | mohan | jun 24 | [email  pretanced] ; |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论