sql server - SQL Database Select, Sort, and Eliminate Duplicates without DISTINCT -
in sample sql database, i've got invoice totals , vendor names on 2 separate tables.
as general orientation, here current code i've created:
select top 5 invoicetotal, vendorname invoices join vendors on invoices.vendorid = vendors.vendorid order invoicetotal desc;
i'm looking top 5 invoice totals displayed without repeating of vendor names. example, current output is:
137966.19 malloy lithographing inc 26881.40 malloy lithographing inc 23517.58 malloy lithographing inc 21842.00 data reproductions corp 20551.18 malloy lithographing inc
however, target output like:
137966.19 malloy lithographing inc 21842.00 data reproductions corp 20076.01 smith & co 14590.00 tim's management ltd 13878.50 helloworld corp
is can make happen in management studio? i've tried implementing distinct, doesn't seem work.
any extremely appreciated.
would following work?
select top 5 max(invoicetotal) total, vendorname invoices join vendors on invoices.vendorid = vendors.vendorid group vendorname order 1 desc
Comments
Post a Comment