Question : Where do I put the brackets

SELECT
<output name="year" replace="YEAR(time)" data="int" />,
<output name="month" replace="MONTHNAME(time)" chart="k" />,
<output name="invoice" chart="d" replace="SUM(invoice)" data="float" />,
<output name="hose" chart="d" replace="SUM(SELECT (v.quantity * s.charges) FROM invitem v LEFT JOIN service s ON v.idservice = s.idservice WHERE v.idservice = 'UTILSRUBBERHOSE657')" />,
<output name="payment" replace="SUM(payment)" chart="d" data="float" />
FROM transac
WHERE time between 'a year ago' AND NOW()
GROUP BY MONTHNAME(time)


I am trying to produce a chart. The query runs ok without the <output name="hose"....., but after I added it, it produce error. Probably the brackets placment is not right because the debug points to a syntax error.

Answer : Where do I put the brackets

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