Hi,
One of us is drunk, MySQL, Code, Me:
The following query, when executed, runs and does everything ok, but it seems to flip between two outcomes…
Run it once, you get say Showing rows 0 - 17 ( 18 total, Query took 0.0729 sec)
Run it a second time, you get say Showing rows 0 - 16 ( 17 total, Query took 0.0698 sec)
Run a third time Showing rows 0 - 18 ( 19 total, Query took 0.0699 sec)
It seems two of the users are often appeaing and disapearing…
Im guessing my query is ridiculos and where it’s doing realtime calculations, it’s causing the different results each time i run it…
Can someone take a look and streamline or do something clever? lol Im sure its very obviously to a DB pro
$query = Yii::app()->db->createCommand(
"SELECT
profiles.user_id AS 'adviser_id',
profiles.firstname AS 'adviser_firstname',
profiles.lastname AS 'adviser_lastname',
users.email AS 'adviser_email',
leads.id_lead AS 'lead_id',
client_1_lastname AS 'client_last_name',
visit_adviser_notified_date AS 'adviser_notified',
DATE_FORMAT(NOW(), '%d/%m/%Y') AS now,
DATEDIFF(CURDATE(),STR_TO_DATE(visit_adviser_notified_date, '%d/%m/%Y')) AS 'days_elapsed',
group_concat(leads.client_1_lastname) AS outstanding_client_names,
group_concat(leads.id_lead) AS outstanding_lead_ids,
count(*) AS outstanding_amount
FROM profiles, users, leads
WHERE profiles.user_id = users.id
AND profiles.user_id = leads.id_user
AND visit_adviser_notified_date != ''
#AND id_user = ".$adviserID."
GROUP BY profiles.user_id
HAVING days_elapsed >=3
ORDER BY outstanding_amount DESC
")->queryAll();