是否可以修改此 Mysql 查询以对同一个 idinvoice 仅显示一次发票
下面的查询
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想显示一次 IDINVOICE,则您的 GROUP BY 应仅包含 IDINVOICE。您必须决定如何显示其他参数(SUM/AVG/随机/无...)。
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...).