mysql - How to find SUM of all rows which have unique value -


i'm making financial script , in end of every month need final sum of invoices. if invoice has 4 or 10 rows every row contains full sum.

so need find distinct invoice numbers , sum value.

select finalprice  invoices  group invoicenumber; 

finalprice

   87.26   153.72    10.56   979.20   136.20    47.10   112.62 

this gives me every unique row doesn't sum them, when try with:

select sum(finalprice)  invoices  group invoicenumber; 

sum(finalprice)

  349.04  1690.92    10.56 11750.4   544.8   141.3  1351.44 

this sums every row in unique invoicenumber, need sum every unique invoice value.

just create derivate table remove duplicates

i belive want single total value dont need group by.

select sum(finalprice)  (select distinct invoicenumber, finalprice       invoices) t; 

also can use version

select sum(finalprice)  (select finalprice        invoices        group invoicenumber) t; 

note: derivated tables need alias use t.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -