私は、各顧客が多くのリクエストを提出できるテーブルを用意していますが、最新のリクエストのみが楽しめます。個別の最新の投稿
たとえば、Customer1は1つの要求を提出し、CustomerXは10個の要求を提出している可能性があります。だから私は、レポートを引き出すと、customer1の1リクエストとCustomerXの10リクエストが表示されます。
どうすればいいですか?
顧客ID、FoodSelection1、FoodSelection2、DateSubmitted
私は、各顧客が多くのリクエストを提出できるテーブルを用意していますが、最新のリクエストのみが楽しめます。個別の最新の投稿
たとえば、Customer1は1つの要求を提出し、CustomerXは10個の要求を提出している可能性があります。だから私は、レポートを引き出すと、customer1の1リクエストとCustomerXの10リクエストが表示されます。
どうすればいいですか?
顧客ID、FoodSelection1、FoodSelection2、DateSubmitted
あなたはROW_NUMBER(と協力しTIES WITH句を使用することができます)
Select Top 1 with ties *
From YourTable
Order By Row_Number() over (Partition By CustomerID Order by DateSubmitted Desc)
select * from MyTable T1
where not exists --exclude records where
(
select 1 from MyTable T2
where T1.[Customer Id]=T2.[Customer Id] --there is matching rcd for customer
and T1.DateSubmitted<T2.DateSubmitted --a newer one exists
)
[Customer Id]とDateSubmittedのインデックスが効率的に動作するようにしたいと考えています。 – jerry
select
t.Customer,
t.id,
t.FoodSelection1,
t.FoodSelection2,
t.DateSubmitted
from MyTable T1 as t
where t.datesubmited in
(select max(r.datesubmited)
from table 1 as r
where t.idCustomer = r.idCustomer
group by r.idcustomer)
あなたでしょうROW_NUMBERを使用します。 https://docs.microsoft.com/en-us/sql/t-sql/functions/row-number-transact-sql –
これまでに何を試しましたか? – lukkea