SELECT SUM(Table.ColumnThatChanges) AS 'Count', Table.B as 'Param'
FROM Table
WHERE Table.C = 4
AND Table.B = 'Something'
AND Table.Date BETWEEN '2014-01-01 00:00:00' AND '2014-06-30 00:00:00'
I have this SQL Query that I generate in php. I want to call this query quite a few times with a slight change; I am changing ColumnThatChanges every request.
What would be the better/fastest way to do this? Use str_replace? Call the entire string everytime? Use some type of class that generates my SQL statement?
I'm currently generating it this way with Zend:
$somequery = $this->db->select();
$somequery->from(Table, array('SUM(Table.ColumnThatChanges) AS Count', 'Table.B as Param'))
->where('C = ?', $Variable)
->where('B = ?', $Variable2)
->where('Date > ?', $start_date)
->where('Date < ?', $end_date);
I haven't had much success changing the ColumnThatChanges part of the query, maybe I'm doing it wrong?