Note that there are some explanatory texts on larger screens.

plurals
  1. POMYSQL Double Nest SELECT
    primarykey
    data
    text
    <p>I have a 'double' nested SELECT statement. The deeper statement pulls the values I need for the per month total I am trying to insert into an existing row. However each "Segment' has differing percentages so it results in multiple rows. To get around this I have an outer select that then does a SUM the result. </p> <p>More problem is I am unable to match the result to the month as the when I try to link to the columns name 'Enrol_month_short' I get the following message.</p> <p>"Unknown column 'Enrol_month_short' in 'where clause'"</p> <pre><code>SELECT Date_format(tbl_client_details.cd_enrol_date, '%b %y')AS Enrol_month_short, Sum(tbl_revenue.rev_value) AS Enrol_Cum_Rev, (SELECT Sum(tbl_revenue.rev_value) FROM tbl_client_details LEFT OUTER JOIN gridlock.tbl_revenue ON tbl_client_details.cd_zbi_no = tbl_revenue.rev_zbi_no AND tbl_client_details.cd_ucn = tbl_revenue.rev_ucn WHERE ( Date_format(tbl_client_details.cd_enrol_date, '%b %y') = enrol_month_short ) AND ( Date_format(rev_month, '%b %y') = enrol_month_short ) GROUP BY Date_format(tbl_client_details.cd_enrol_date, '%b %y')) AS New_client_rev, (SELECT Count(tbl_client_details.cd_id) FROM tbl_client_details WHERE ( tbl_client_details.cd_enrol_date &gt;= '2012-04-01' AND tbl_client_details.cd_enrol_date &lt;= '2012-07-31' ) AND Date_format(tbl_client_details.cd_enrol_date, '%b %y') = enrol_month_short GROUP BY Date_format(tbl_client_details.cd_enrol_date, '%b %y')) AS Actual_Enrols, (SELECT ( ( Sum(tbl_revenue.rev_value) * ( tbl_segment.seg_growth_2012 / 100 ) ) / 12 ) AS YEAR_NEW_BUS_BUDGET FROM tbl_client_details LEFT OUTER JOIN tbl_revenue ON tbl_client_details.cd_zbi_no = tbl_revenue.rev_zbi_no AND tbl_client_details.cd_ucn = tbl_revenue.rev_ucn LEFT OUTER JOIN tbl_segment ON tbl_client_details.cd_segment = tbl_segment.seg_name WHERE ( rev_month &gt;= '2012-04-01' AND rev_month &lt;= '2012-07-31' ) GROUP BY enrol_month_short) AS YEAR_NEW_BUS_BUDGET FROM tbl_client_details LEFT OUTER JOIN gridlock.tbl_revenue ON tbl_client_details.cd_zbi_no = tbl_revenue.rev_zbi_no AND tbl_client_details.cd_ucn = tbl_revenue.rev_ucn WHERE ( tbl_client_details.cd_enrol_date &gt;= '2012-04-01' AND tbl_client_details.cd_enrol_date &lt;= '2012-07-31' ) AND ( rev_month &gt;= '2012-04-01' AND rev_month &lt;= '2012-07-31' OR rev_month = NULL ) GROUP BY enrol_month_short ORDER BY tbl_client_details.cd_enrol_date; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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