I have created a table that I need for a report.
$sql = "CREATE TABLE survey_results_BC_temp
SELECT sr.taxyear,sr.user_email, sr.item, sr.campaign, sr.email, sr.qualified, COUNT(distinct sr.number_of_employees) as number_of_employees, e.w2_wages
FROM survey_results sr JOIN employees e
ON user_email=employee_email AND sr.taxyear=e.taxyear
WHERE item_type='BC' and sr.campaign=?
GROUP BY taxyear,user_email
";
$query1 = $this->db->query($sql,$campaign);
$sql ="ALTER TABLE survey_results_BC_temp
ADD dollars_per_BC int default 0,
ADD number_consultants int default 0,
ADD number_contracts int default 0,
ADD amount int default 0,
ADD number_of_bus_comps int default 0"
;
$query2 = $this->db->query($sql);
Besides the fields I already assembled, I need the total # of business_components used. To get this I have fallen back to mysql and used this. I of course would have preferred to have it created directly in the CREATE TABLE statement above for speed purposes. My code is already way too slow.
$sql = "SELECT COUNT(bus_comp) as buscomp_count
FROM business_components WHERE email = ? AND campaign = ? AND taxyear=(SELECT taxyear FROM survey_results_BC_temp WHERE campaign=? AND email = ?) ";
$query = $this->db->query($sql, array($email,$campaign,$campaign,$email,));
$row = $query->result();
$buscomp_count=$row[0]->buscomp_count;
This directly gets the number of business components from a different table. Is there any way for me to directly insert the $buscomp_count into the field number_of_bus_comps in the survey_results_BC_temp datastore I will build?