Q.最後の12か月間に取引に記載されていなかった製品の名前を一覧表示します。SQL:これに対して適切なクエリは何ですか?
お得な表
i. Deal_id
ii. Product_id
iii. Deal_start_date
iv. Deal_end_date
製品薄暗い表
i. Product_id
ii. Product_name
iii. Manufacturer
私の答えは次のとおりです。
Select Product_name, Rank() over(partition by year(Deal_start_date) order by Deal_start_date desc) as Deal_date
From Product Dim Table
Right join Deals Table on Product Dim Table.Product_id=Deals Table.Product_id
where Deal_date > 1
Group by Product_name
Order by Deal_date desc
互換性のないデータベース製品を削除しました。実際に使用しているDBMSに戻ってください。 – Siyual
'プロダクトPから選択する*存在しない(ここではD.Product_Id = P.Product_IDとD.Deal_End_Date> =" today-12 months "'を選択します。今日の12ヶ月は使用するRDBMSに固有です。 – xQbert