How to remove duplicates in SQL Server -


i have data looks this:

order no.  name    date   unit price  freight 001        abc     1-16    232         25 001        abc     1-16    55          25 001        abc     1-16    156         25 002        def     2-5     478         16 002        def     2-5     356         16 

i trying let freight cost show once in table, result like:

order no.  name    date   unit price  freight 001        abc     1-16    232         25 001        abc     1-16    55          0 001        abc     1-16    156         0 002        def     2-5     478         16 002        def     2-5     356         0 

please me this

here query want:

select      order_no, name, thedate, unit_price,      case          when row_number() on (partition order_no order order_no) = 1 freight         else 0      end freight yourtable 

this looks @ rows each order number , provides row number. if it's row 1 of order uses values of freight column, otherwise uses 0.

note i'm assuming freight value same across rows same order number.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -