选择具有内部联接和最大ID的行 [英] Select rows with inner join and max id

查看:50
本文介绍了选择具有内部联接和最大ID的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我写了这个查询但是它并不完全正确。

在我的数据库中有更多的表,其中一个表包含更多的行一个产品(价格)。

因此,当我想从发票中选择记录时,例如来自另一个id的相同id和2个产品的3个产品,它必须显示该发票中的所有行但是最后加价了。


这是我目前的查询:

展开 | < span class =codeLinkonclick =selectAll(this);>选择 | 换行 | 行号

解决方案

如果你发布了som e样本数据和预期结果。


让我们试试:

上周我卖了1个激光和1个灯光效果。

但激光器在他的桌子上有2个价格(producten_prijzen)

当我推出时,这个出现了:

Laser American Dj micro galaxian 0,00 1 95,00 95,00

Laser American Dj micro galaxian 0,00 1 95,00 95,00

Led effect American Dj Jewel领衔0,00 1 69,00 69,00


所以我最后用GROUP BY改了它

所以我认为它很好......

但是今天我发了一个服务发票。

有1个产品叫做服务,价格是1。

所以,当我开发票时,它看起来像这样:


服务人工小时​​29-6-2011 0,00 5 30,00 150,00

服务人工小时​​27-6-2011 0,00 3 30,00 90,00

服务人工小时​​28-6-2011 0,00 4 30,00 120,00


但是现在查询返回此...

服务人工小时​​29-6-2011 0,00 5 30,00 150,00


那是'它...


希望这个更清楚?

问候,

Paul


< blockquote>我仍然不明白。


我不知道激光和LED产品与你的例子有什么关系。你提到它们但在你的例子中不再使用它们。


另外,你不能说你得到的结果有什么问题而且你没有说出你期待的结果。


Hello,
I have wrote this query but it''s not completely right.
In my database are more tables and 1 of those tables contains more rows about a product (prices).
So when i want to select the records from a invoice with for example 3 products from the same id en 2 products from another id, it has to show all rows in that invoice but with the last added price.

This is my query so far:

Expand|Select|Wrap|Line Numbers

解决方案

It would if you posted some sample data and expected results.


Let''s try:
Last week i sold 1 laser and 1 light effect.
But the laser had 2 prices in his table (producten_prijzen)
When i roll it out this came up:
Laser American Dj micro galaxian 0,00 1 95,00 95,00
Laser American Dj micro galaxian 0,00 1 95,00 95,00
Led effect American Dj Jewel led 0,00 1 69,00 69,00

So i changed it at the end with a GROUP BY
So i thought it was good...
But today i made a invoice for services.
In there was 1 product called services with 1 price.
So, when i made the invoice, it looks like this:

Services Labour hour 29-6-2011 0,00 5 30,00 150,00
Services Labour hour 27-6-2011 0,00 3 30,00 90,00
Services Labour hour 28-6-2011 0,00 4 30,00 120,00

But now the query returned this...
Services Labour hour 29-6-2011 0,00 5 30,00 150,00

And that''s it...

Hope this is more clear?
Regards,
Paul


I still don''t understand.

I don''t see what the laser and led products have to do with your example. You mention them but then don''t use them any further in your example.

Plus, you don''t say what is wrong with the results you got and you don''t say what results you''re expecting.


这篇关于选择具有内部联接和最大ID的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆