簡體   English   中英

MS Access查詢以從表中獲得不同的記錄

[英]MS Access Query to get Distinct records from a table

我有一個如下表:

ID  Demand_ID   Supply_ID   Supply_Skill    Supply_Designation  Supply_Location
1   D10         S10         Python          engineer            Mumbai
2   D10         S16         Python          engineer            Mumbai
3   D10         S2          Python          engineer            Mumbai
4   D10         S7          Python          engineer            Mumbai
5   D12         S12         Java            Manager             Bangalore
6   D1          S1          Java            Senior engineer     Bangalore
7   D1          S11         Java            Senior engineer     Bangalore
8   D1          S3          Java            Senior engineer     Bangalore
9   D2          S10         Python          engineer            Mumbai
10  D2          S16         Python          engineer            Mumbai
11  D2          S2          Python          engineer            Mumbai
12  D2          S7          Python          engineer            Mumbai
13  D3          S1          Java            Senior engineer     Bangalore
14  D3          S11         Java            Senior engineer     Bangalore
15  D3          S3          Java            Senior engineer     Bangalore

如何獲得唯一的記錄,如下所示:

ID  Demand_ID   Supply_ID   Supply_Skill    Supply_Designation  Supply_Location
1   D10         S10         Python          engineer            Mumbai
5   D12         S12         Java            Manager             Bangalore
6   D1          S1          Java            Senior engineer     Bangalore
10  D2          S16         Python          engineer            Mumbai
14  D3          S11         Java            Senior engineer     Bangalore

請告訴我一個邏輯來獲得獨特的記錄,像上面,並用以下條件就像從數據Supply_IDSupply_Location不應該被重復的Demand_ID

像上面的示例一樣, Demand_Id D10D2具有相同的下一列記錄集。 如果該列之一與D10匹配,則不應為D2重復。 對於D2它可以從相應列中選取任何記錄,但已從D10選取的記錄除外。

您描述的並不是完全獲得不同的記錄(因為原始表具有不同的記錄),而是獲得每個Demand_Id的第一條記錄。

SELECT *
  FROM Supplies_And_Demands
 WHERE ID IN (SELECT MIN(ID)
                FROM Supplies_And_Demands
               GROUP BY Demand_Id)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM