views:

20

answers:

1

The query below

SELECT
<output name="c.name" title="Name" />,
<output name="c.reference" title="Reference No." />,
<output name="i.idinvoice" title="Invoice ID" />,
<output replace="(SUM(v.quantity * s.charges))/COUNT(i.idinvoice)" />As Invoice
<output replace="p.amount" />AS Amount,
<output replace="p.idpayment" title="Payment ID" />,
<output replace="p.cheque_no title="Cheque No" />,
<output replace="p.pdatetime" title="Processed Time" />,
<output replace="p.user" title="Processed By" type="user" attribute="username" />
FROM inv i
LEFT JOIN invitem v ON v.idinvoice = i.idinvoice
LEFT JOIN service s ON s.idservice = v.idservice
LEFT JOIN payment p ON p.idinvoice = i.idinvoice
LEFT JOIN address a ON a.idaddress = i.idaddress
LEFT JOIN client c ON c.idclient = a.idclient
WHERE a.idaddress = '<input name="idaddress" />'
GROUP BY i.idinvoice, p.amount, p.idpayment, p.cheque_no, p.pdatetime, p.user
ORDER BY i.idinvoice DESC
A: 

If you only want the idinvoice shown once, your GROUP BY should only include the IDINVOICE. You'll have to decide how to display the other parameters (SUM/AVG/random/none...).

SELECT
<output name="c.name" title="Name" />,
<output name="c.reference" title="Reference No." />,
<output replace="i.idinvoice" title="Invoice ID" />,
<output replace="(SUM(v.quantity * s.charges))/COUNT(i.idinvoice)" />AS Invoice,
<output replace="(p.amount)" data="float" />As Amount,
<output name="p.idpayment" title="Payment ID" />,
<output replace="p.cheque_no" title="Cheque No" />,
<output replace="p.pdatetime" title="Processed Time" />,
<output replace="p.user" title="Processed By" type="user" attribute="username" />
FROM inv i
LEFT JOIN invitem v ON v.idinvoice = i.idinvoice
LEFT JOIN service s ON s.idservice = v.idservice
LEFT JOIN payment p ON i.idinvoice = p.idinvoice
LEFT JOIN address a ON a.idaddress = i.idaddress
LEFT JOIN client c ON c.idclient = a.idclient
WHERE a.idaddress = '<input name="idaddress" />'
GROUP BY i.idinvoice
ORDER BY i.idinvoice DESC
Konerak
the UI is at http://picasaweb.google.com/rroslan/Web#5492894295897244242
roslan
Ok. So if you only want to display one line for invoiceID 295, what data would you want to put in the other columns? For example, in Amount?
Konerak
If we can use IF idinvoice same as previous then no display for the next row, column Amount
roslan
That's more a GUI question than a MySQL question. Change your GUI to hide the value or merge the rows - depending on your GUI's capabilities.
Konerak
Can I do this"IF((idinvoice == idinvoice-1),'',(SUM(v.quantity * s.charges))/COUNT(i.idinvoice)" (though idinvoice-1 is not quite right, it should be previous idinvoice. If I can get the previous idinvoice expression, then this might work.
roslan
This snippet below uses the same GUI and makes the data visible if published. Going along the same line, I was thinking that it is possible to do the same if I can get the previous idinvoice expression.replace="IF(published, a.idaddress,'')
roslan
I am sorry. You are right. It cannot be done using just Mysql
roslan