Link to home
Start Free TrialLog in
Avatar of gosi75
gosi75Flag for Iceland

asked on

Dublicated rows by certain critera

I have rows in my Salestable where I want to find duplicated rows with different salesid.

F.ex. There is a transaction where CustomerKey, Quantity, AccountNumber is dublicated in the database.
The only thing that is not the same is the SalesOrderId but to know that there is a dublicated transaction,
the other SalesOrderID with the same CustomerKey, Quantity and Accountnumber are the same, but the transaction
createddatetime is within 5 minutes between those two transactions.

Any Idea how I could write my query to find all SalesOrderId where above criteria is matched?

f.ex.

SalesOrderID    Customerkey      AccountNumber        Quantity                  CreatedDateTime
5001                 250                                1100                  1350                        2015-08-19 09:16:31.000
5002                 250                                 1100                  1350                     2015-08-19 09:20:01.000
Avatar of Vikas Garg
Vikas Garg
Flag of India image

HI,

You can try this

SELECT *,ROW_NUMBER()OVER(PARTITION BY CUSTOMERKEY, ACCOUNTNUMBER,QUANTITY ORDER BY SALESORDERID) RN FROM TABLE

Open in new window


The above query will tell you about the records having different salesorderid but common customerkey,accountnumber and quantity.
such records will have RN column having value > 1.

Hope this would help you ...
ASKER CERTIFIED SOLUTION
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
gosi75, do you still need help with this question?