Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql where clause spanning multiple years?
    primarykey
    data
    text
    <p>I have mysql query that outputs years leads v sales and calculates the conversions rates which worked great in 2012 as it only held a years data. Now its 2013 I need to change how it works but have become stuck. If a lead came in December 2012, then became a sale in 2013 its is ommitted from my query output as it only asks for CaseDate of 2013.</p> <pre><code>Select q.*, ROUND(100 * q.Comms / q.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, ..... Dec Sum(Case When Year(b.CaseDate) = 2013 And Month(b.CaseDate) Between '1' And '12' Then 1 Else 0 End) As Total, Sum(Case When (Year(b.CaseDate) = 2012 Or Year(b.CaseDate) = 2013) And Year(b.StatusSubmittedDate) = ".(int)$_POST['year']." And Month(b.StatusSubmittedDate) Between ".(int)$_POST['start']." And ".(int)$_POST['end']." Then 1 Else 0 End) As Comms From tblcontacts a Inner Join tblcases b On a.ContactID = b.ContactAssignedTo Group By a.ContactFullName With Rollup) q </code></pre> <p>This works;</p> <pre><code>Sum(Case When (Year(b.CaseDate) = 2012 Or Year(b.CaseDate) = 2013) And Year(b.StatusSubmittedDate) = 2013 And Month(b.CaseDate) Between '1' And '12' Then 1 Else 0 End) As Comms </code></pre> <p>This donly shows leads entered &amp; submitted in 2013;</p> <pre><code>Sum(Case When (Year(b.CaseDate) = 2012 Or Year(b.CaseDate) = 2013) And Year(b.StatusSubmittedDate) = ".(int)$_POST['year']." And Month(b.CaseDate) Between ".(int)$_POST['start']." And ".(int)$_POST['end']." Then 1 Else 0 End) As Comms </code></pre> <p>Many Thanks</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.
    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