Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Superfinboy
Starting Member
2 Posts |
Posted - 2012-07-02 : 14:36:12
|
I have to write a selec statement that answers this question. Write a SELECT statement that answers this question: Which invoices have a PaymentTotal that’s greater than the median PaymentTotal for all paid invoices? (The median marks the midpoint in a set of values; an equal number of values lie above and below it.) Return the InvoiceNumber and InvoiceTotal for each invoice.Hint: Begin with the solution to exercise 2, then use the ALL keyword in the WHERE clause and code “TOP 50 PERCENT PaymentTotal” in the subquery.This is what i have so far and i'm not sure what i'm doing wrong. Select VendorId, PaymentTotal, InvoiceNumber, InvoiceTotalFrom InvoicesWhere PaymentTotal > All (SELECT TOP 50 Percent(PaymentTotal) From Invoices)Order By VendorID, PaymentTotaland nothing for my output which i don't think is correct. I'm thinking maybe i need to filter out something but im not sure how to. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-02 : 19:29:53
|
[code]Select VendorId, PaymentTotal, InvoiceNumber, InvoiceTotalFrom InvoicesWhere PaymentTotal > All(SELECT TOP 50 Percent(PaymentTotal)From InvoicesORDER BY PaymentTotal ASC)Order By VendorID, PaymentTotal[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|