SQL 加入两个脚本

SQL Join for two scripts

我正在尝试加入两个脚本

--script 1         
select  
    t.vendor_code,
    RTRIM(LTRIM(cast(datename(month, [CLOSED_DATE]) as char(15))))+',' + RTRIM(LTRIM(cast(year([CLOSED_DATE]) as char(20)))) as [CLOSED_DATE],
    count(t.vendor_code) as [No_of_Case] 
from 
    dbo.FTX_FA_CASE t WITH (NOLOCK) 
where 
    [CLOSED_DATE] is not null 
group by  
    t.vendor_code, CLOSED_DATE

--script 2  
SELECT  
    (RTRIM(LTRIM(cast(datename(month, [dates]) as char(15))))+',' + RTRIM(LTRIM(cast(year([dates]) as char(20)))) + ',') 
FROM 
    efoxsfc.dbo.FTX_FA_Calender 
WHERE 
    1 = 1 
    AND CAST(dates AS DATETIME) >= DATEADD(mm, -5 ,DATEADD(m, DATEDIFF(m, 0,GETDATE()), 0)) 
    AND dates <= DATEADD(m, DATEDIFF(m, 0,GETDATE()), 0)    

其中 return 数据是这样的:

我想要一个 return 这个输出的脚本:

基本上我试图从第一个 table 获取第二个 table 和 no_of_Case 的所有数据。第一个脚本中不存在的月份,因为 no_of_case 值应为“0”。

请指教!!

试试这个

select 
    name, 
    (select distinct date 
     from Table_1 t2 
     where t1.date = t2.date),
    count([no of count]) 
from
    Table_1 t1
group by 
    name, date