Question : These joins baffles me

This is my query:

SELECT
<output name="MONTHNAME(i.datetime)" chart="k" />AS Month,
<output replace="(SUM(p.quantity * s.charges))" data="float" chart="d" />AS Invoice,
<output replace="amount" data="float" chart="d" />AS Payments,
<output replace="service" data="float" chart="d" />AS service
FROM invitem p
LEFT JOIN inv i ON i.idinvoice = p.idinvoice
LEFT JOIN service s ON s.idservice = p.idservice
LEFT JOIN
(SELECT (s.charges * p.quantity) AS service FROM invitem p  
LEFT JOIN service s ON s.idservice = p.idservice
WHERE s.service = 'PARTS-LIGHTS-VBFG-2'
GROUP BY MONTNAME(p.datetime)) m
LEFT JOIN (select idinvoice, sum(amount) as amount
FROM payment p group by MONTHNAME(p.datetime)
GROUP BY MONTHNAME(p.datetime)

and I am getting this error

[2010-07-25T21:13:11-05:00] LQMConnectionSQLMysqli: Cannot execute query '
SELECT
MONTHNAME(i.datetime)AS Month,
(SUM(p.quantity * s.charges))AS Invoice,
amountAS Payments,
serviceAS service
FROM invitem p
LEFT JOIN inv i ON i.idinvoice = p.idinvoice
LEFT JOIN service s ON s.idservice = p.idservice
LEFT JOIN
(SELECT (s.charges * p.quantity) AS service FROM invitem p
LEFT JOIN service s ON s.idservice = p.idservice
WHERE s.service = 'PARTS-LIGHTS-VBFG-2'
GROUP BY MONTNAME(p.datetime)) m
LEFT JOIN (select idinvoice, sum(amount) as amount
FROM payment p group by MONTHNAME(p.datetime)
GROUP BY MONTHNAME(p.datetime)
' using connection Joomla (1): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY MONTHNAME(p.datetime)' at line 16 ( /home/roslan/webapps/joomla2/plugins/gmitc/lqm/connection/sql/mysqli.php:173)


Explanation on what I want to do

I am using joomla as a framework to use an off the selves joomla component, LFRM. I can create forms and grid outtput the extjs way, just by typing mysql code and intermix with a bit of xml. The author says what you can do on PuTTy, you can do with LFRM.

For printed output I have to do a bit of php. Though I do not come from a programming background, my brother's college is using it for accounts and student's results slip since a year ago. So you see that LFRM is a good teaching tool.

I am trying to produce a chart with time, MONTH as the key and invoice, payments and a service as data on the chart.

Answer : These joins baffles me

ok, I got it working

SELECT
<output name="year" replace="(YEAR(t.time))" />AS year,
<output name="month" replace="(MONTHNAME(t.time))" chart="k" />AS month,
<output name="invoice" replace="(SUM(t.invoice))" chart="l" data="float" />AS invoice,
<output name="payments" replace="(SUM(t.payment))" chart="l" data="float" />AS payments,
<output name="lights" replace="CAST((SUM(service)) AS Decimal(8,2))" chart="d" data="float" />AS lights,
<output name="lights2" replace="CAST((SUM(service2)) AS Decimal(8,2))" chart="d" data="float" />AS lights2,
<output name="hose" replace="CAST((SUM(hose)) AS Decimal(8,2))" chart="d" data="float" />AS hose
FROM transac t
LEFT JOIN (SELECT v.datetime AS datetime, (v.quantity * s.charges) AS service FROM invitem v LEFT JOIN service s ON s.idservice = v.idservice WHERE s.idservice = 'PARTS-LIGHTS-VBFG-2' GROUP BY v.datetime) z ON z.datetime = t.time
LEFT JOIN (SELECT v.datetime AS datetime, (v.quantity * s.charges) AS service2 FROM invitem v LEFT JOIN service s ON s.idservice = v.idservice WHERE s.idservice = 'PARTS-LIGHT-FGRT-1' GROUP BY v.datetime) y ON y.datetime = t.time
LEFT JOIN (SELECT v.datetime AS datetime, (v.quantity * s.charges) AS hose FROM invitem v LEFT JOIN service s ON s.idservice = v.idservice WHERE s.idservice = 'UTILSRUBBERHOSE657' GROUP BY v.datetime) w ON w.datetime = t.time
WHERE DATE(time) between 'a year ago' AND DATE(NOW())
GROUP BY MONTHNAME(t.time)
Random Solutions  
 
programming4us programming4us