Note that there are some explanatory texts on larger screens.

plurals
  1. POMysql where clause breaks calculated query
    primarykey
    data
    text
    <p>wonder if someone can point out the error in my code below. I have mysql query that displays sales leads by month, then calculates % of those converted to sales. If I add where clause to this it breaks the total column as it outputs the same as the Comms column?</p> <pre><code> 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 </code></pre> <p>Without WHERE clause it outputs;</p> <pre><code>Total - Comms - Conversion 479 - 148 - 30.9% </code></pre> <p>With WHERE clause it outputs;</p> <pre><code>Total - Comms - Conversion 148 - 148 - 100% </code></pre> <p>I cant work out why this has happened?</p> <p>Kind Regards</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload