想知道是否有人可以指出我下面代码中的错误。我有 mysql 查询,按月显示销售线索,然后计算转化为销售额的百分比。如果我在其中添加 where 子句,它会破坏总列,因为它的输出与 Comms 列相同?
Select
q.*,
ROUND(100 * Comms / Total, 2) As Conversion,
If(q.Adviser Is Null, 1, 0) As remove
From
(Select
a.ContactFullName As Adviser,
SUM(YEAR(b.CaseDate) = 2013 AND Month(b.CaseDate) = 1) AS Jan,
SUM(YEAR(b.CaseDate) = 2013 AND Month(b.CaseDate) = 2) As Feb,
SUM(YEAR(b.CaseDate) = 2013 AND Month(b.CaseDate) = 3) As Mar,
SUM(YEAR(b.CaseDate) = 2013 AND Month(b.CaseDate) = 4) As Apr,
SUM(YEAR(b.CaseDate) = 2013 AND Month(b.CaseDate) = 5) As May,
SUM(YEAR(b.CaseDate) = 2013 AND Month(b.CaseDate) = 6) As Jun,
SUM(YEAR(b.CaseDate) = 2013 AND Month(b.CaseDate) = 7) As Jul,
SUM(YEAR(b.CaseDate) = 2013 AND Month(b.CaseDate) = 8) As Aug,
SUM(YEAR(b.CaseDate) = 2013 AND Month(b.CaseDate) = 9) As Sep,
SUM(YEAR(b.CaseDate) = 2013 AND Month(b.CaseDate) = 10) As Oct,
SUM(YEAR(b.CaseDate) = 2013 AND Month(b.CaseDate) = 11) As Nov,
SUM(YEAR(b.CaseDate) = 2013 AND Month(b.CaseDate) = 12) As Dece,
Count(b.CaseID) As Total,
Sum(Case When Year(b.StatusSubmittedDate) = 2013 Then 1 Else 0
End) As Comms
From
tblcontacts a Inner Join
如果没有 WHERE 子句,它会输出;
Total - Comms - Conversion
479 - 148 - 30.9%
使用 WHERE 子句输出;
Total - Comms - Conversion
148 - 148 - 100%
我无法弄清楚为什么会发生这种情况?
亲切的问候