分组子查询并使用concat_ws()分开并组合结果集

发布于 2025-02-13 07:27:00 字数 5044 浏览 0 评论 0 原文

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] ;

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 protected]; [email protected]
[email protected] mohan jun 24 [email protected]; [email protected]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文