Re: ugly SQL for a report...

2006-05-30 Thread Cory Robin
Slightly new query.. Here's the new query and results of an explain.. I'm thinking that some indexing would help.. However, I don't really know where to start. --- EXPLAIN SELECT pnr.ID ID_pnr, pnr.reservationdatetime, pnr.conf_number, pnr.created_by,

ugly SQL for a report...

2006-05-29 Thread Cory
I have the following query that is running VERY slowly. Anyone have any suggestions? --- SELECT pnr.ID ID_pnr, pnr.reservationdatetime, pnr.conf_number, pnr.created_by, GROUP_CONCAT(pp.name_last,', ',pp.name_first ORDER BY name_last DESC SEPARATOR 'br') names, (SELECT

Re: ugly SQL for a report...

2006-05-29 Thread Jochem van Dieten
On 5/29/06, Cory wrote: I have the following query that is running VERY slowly. Anyone have any suggestions? --- SELECT pnr.ID ID_pnr, pnr.reservationdatetime, pnr.conf_number, pnr.created_by, GROUP_CONCAT(pp.name_last,', ',pp.name_first ORDER BY name_last DESC SEPARATOR 'br') names, (SELECT

Re: ugly SQL for a report...

2006-05-29 Thread Cory Robin
SELECT pnr.ID ID_pnr, pnr.reservationdatetime, pnr.conf_number, pnr.created_by, GROUP_CONCAT(pp.name_last,', ',pp.name_first ORDER BY name_last DESC SEPARATOR 'br') names, (SELECT SUM(pf.base_fare*(SELECT COUNT(1) FROM pnr_passengers pp WHERE pp.ID_pnr=pnr.ID )) FROM pnr_fares

Re: ugly SQL for a report...

2006-05-29 Thread Jochem van Dieten
On 5/29/06, Cory Robin wrote: SELECT pnr.ID ID_pnr, pnr.reservationdatetime, pnr.conf_number, pnr.created_by, GROUP_CONCAT(pp.name_last,', ',pp.name_first ORDER BY name_last DESC SEPARATOR 'br') names, (SELECT SUM(pf.base_fare*(SELECT COUNT(1) FROM pnr_passengers pp WHERE

Re: ugly SQL for a report...

2006-05-29 Thread Peter Brawley
Cory, One way to lose the duplicate queries is to assign the count per pnr.id to a user var, and calculate via that value: SELECT pnr.ID AS ID_pnr, pnr.reservationdatetime, pnr.conf_number, pnr.created_by, ( SELECT @pp_cnt := COUNT(1) FROM pnr_passengers pp WHERE pp.ID_pnr = pnr.ID