How To Eliminate Duplicates In Sql Query

Sql

How To Filter Duplicates In Sql Query

Find duplicates in sql query

How To Eliminate Duplicates In Sql Query File

I recieve duplicate customer bill data which I want to consolidate using SQL query. The divine madman ebook. How to summarize data using single query.both Qty and Price. If either one of price or qty is -ve then both should be -ve.Here is example data for one customer.1 – Only Qty is negativeProduct Qty PriceShirt 2 6.00Shirt -1 6.00-Shirt 1 6.00 Result2 - Only price is negativeProduct Qty PricePant 2 6.00Pant 1 -6.00-Pant 1 6.00 ResultThanks for help!!Pintoo. Code SnippetDECLARE @MyTable table( Product varchar(20),Qty int,Price decimal(8,2))INSERT INTO @MyTable VALUES ( 'Shirt', 2, 6.00 )INSERT INTO @MyTable VALUES ( 'Shirt', -1, 6.00 )INSERT INTO @MyTable VALUES ( 'Pant', 2, 6.00 )INSERT INTO @MyTable VALUES ( 'Pant', 1, -6.00 )SELECTProduct,Qty = sum( CASEWHEN Price. Code SnippetDECLARE @MyTable Table( Product varchar(20),Qty int,Price decimal(8,2))INSERT INTO @MyTable VALUES ( 'Shirt', 2, 6.00 )INSERT INTO @MyTable VALUES ( 'Shirt', -1, 6.00 )INSERT INTO @MyTable VALUES ( 'Pant', 2, 6.00 )INSERT INTO @MyTable VALUES ( 'Pant', 1, -6.00 )INSERT INTO @MyTable VALUES ( 'Shirt', -1, 6.00 )INSERT INTO @MyTable VALUES ( 'Pant', 2, -6.00 )SelectProduct, Sum( Price. Qty / abs( Price )), Sum( Price.

Qty )From @MyTableGroup By ProductProduct-Pant -1.0 -6.00Shirt.0.00.