人物と請求書の2つのテーブルがあります。 人数ごとに多くの請求書行があり、最後の請求書金額のすべての人物情報を選択します。2つ目のテーブルの条件付き複数テーブル結合
人
code | Name | ....
1 | name1
2 | name1
3 | name1
請求書
ID | person_code | amount | date
1 | 2 | 30000 | 12
2 | 1 | 40000 | 10
3 | 3 | 50000 | 12
4 | 2 | 60000 | 14
5 | 3 | 70000 | 12
6 | 2 | 80000 | 12
7 | 1 | 90000 | 18
私は
person code | person name | last amount
1 | name1 | 90000
2 | name2 | 60000
3 | name3 | 70000
または
を選択します3210SELECT person.code , person.name , lastinvoice.amount
FROM person
LEFT JOIN
(SELECT * FROM invoice where invoice.person_code=person.code order by date, ID) as
lastinvoice ON lastinvoice.person_code = person.code
は、このクエリは、MSへのアクセスでは動作しません:
select * from invoice as i where id=(select max(id) from invoice where personCode=i.personcode and date=(select max(date) from invoice where personCode=i.PersonCode
このクエリは、2つの内の選択 – Hamid
と低い性能を有していると私は両方のMS SQL上でそれを実行したいですmsアクセスにはアクセスできませんが、このquryはアクセスできません。 – Hamid
@Hamid:これを基盤として使用して構築してください。コピー/ペースト可能なコードを手渡すと約束した人はいません。 – cHao