我有两个表,票据和行李。我需要一个客户曾经购买过的所有产品。我已经得到这个工作:MySQL查询,两个表与订单组
SELECT referencia, codcliente, pvpunitario, t2.fecha FROM
lineasfacturascli T1
INNER JOIN facturascli T2 ON T1.idfactura = T2.idfactura
WHERE T2.codcliente = "000001"
GROUP BY referencia
但我需要得到的最后价格,客户已经支付了每一件产品。我试图通过"fecha"->(date)
订购,但它不起作用。
表结构
facturascli
idfactura(id bill),
codcliente(client id),
fecha(date)
lineasfacturascli
referencia(name of product),
idfactura(id bill)
pvpunitario(price)
编辑
DRapp解决方案的工作,但我还需要处理一个客户买它在同一天的情况下只得到更低的价格:
随着提供的解决方案是:
|Referencia| |MostRecentDatePerItem| |MostRecentPricePerItem|
| pendrive | | 2017-03-02 | | 50 |
| pendrive | | 2017-03-02 | | 10 |
| samsung | | 2017-03-02 | | 50 |
| linux car| | 2017-04-26 | | 9.99 |
我需要:
|Referencia| |MostRecentDatePerItem| |MostRecentPricePerItem|
| pendrive | | 2017-03-02 | | 10 |
| samsung | | 2017-03-02 | | 50 |
| linux car| | 2017-04-26 | | 9.99 |
感谢
that qeury does not work ok ... https://www.psce.com/blog/2012/05/15/mysql-mistakes-do-you-use- group-by-incorrect/ –
请参阅http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-bea-a-非常简单的sql查询 – Strawberry