1

我有两个查询产生结果:

Date    Count of Converted Leads
07/22/2013  3
07/23/2013  10
07/24/2013  4
07/25/2013  5
07/26/2013  3
07/27/2013  3
--and
Date    Count of All Leads
07/22/2013  105
07/23/2013  517
07/24/2013  291
07/25/2013  170
07/26/2013  122
07/27/2013  79
07/28/2013  86

我想将这些组合成 3 列结果:

Date    Count of Converted Leads      Count of All Leads

出错”子查询返回超过 1 个值

Select convert(varchar(10), [LeadCreatedDate], 101) as Date
,(select count(leadid)  
    from [dbo].[SalesforceProspectConversion]
    where [LeadCreatedDate] between '2013-07-22' and '2013-07-29'
    and [LeadSourceOriginal] != 'Jigsaw' 
    and [LeadSourceOriginal] != 'Other' 
    and [LeadConverted] = 'Y'
    Group by convert(varchar(10), [LeadCreatedDate], 101)) as 'Count of       Converted Leads'
,(select count(leadid)  
    from [dbo].[SalesforceProspectConversion]
    where [LeadCreatedDate] between '2013-07-22' and '2013-07-29'
    and [LeadSourceOriginal] != 'Jigsaw' 
    and [LeadSourceOriginal] != 'Other' 
    Group by convert(varchar(10), [LeadCreatedDate], 101)) as 'Count of All   Leads'
from [dbo].[SalesforceProspectConversion]
where [LeadCreatedDate] between '2013-07-22' and '2013-07-29'
and [LeadSourceOriginal] != 'Jigsaw' 
and [LeadSourceOriginal] != 'Other' 
Group by convert(varchar(10), [LeadCreatedDate], 101)
4

2 回答 2

1

您不再希望您的 Group by 在子查询中。如果您想走这条路线(子查询),您只需要一个子查询(用于转换的潜在客户的计数;对于总计数,您可以使用 count(leadid) 作为父选择中的第二个字段)。然后删除子查询中 where 子句的日期范围部分,并引用日期相等的父驱动程序表(使用表别名来执行此操作)。如果您需要更具体的细节,请告诉我。

于 2013-08-01T22:01:21.900 回答
0

这行得通!

select convert(varchar(10), [LeadCreatedDate], 101) as Date
          ,sum(case when leadconverted = 'Y' then 1 else 0 end) as 'Count of Converted     Leads'
          ,count(leadid) as 'Count of All Leads'
from [dbo].[SalesforceProspectConversion]
where [LeadCreatedDate] between '2013-07-22' and '2013-07-29'
and [LeadSourceOriginal] != 'Jigsaw' 
and [LeadSourceOriginal] != 'Other' 
Group by convert(varchar(10), [LeadCreatedDate], 101)
Order by convert(varchar(10), [LeadCreatedDate], 101) 
于 2013-08-02T17:24:02.113 回答