Need help with query on Microsoft SQL Server 2008?
-
I need to write a query that shows the most profitable order. The profit is shown on the "Extended Price" column. Here is what my output looks like: https://docs.google.com/spreadsheet/ccc?key=0AkyLVhiCpjaFdG5MT3ZsV2hiS1dWR21Vc3MxMmthS3c#gid=0 Here is what the output is supposed to look like: https://docs.google.com/spreadsheet/ccc?key=0AkyLVhiCpjaFdEJaX2hmRjZIZVMtckE4SEVOd0hMT1E#gid=0 Here is my coding so far. It comes from a view called "VExtendedDiff" SELECT OrderID "Order Number", OrderDate "Order Date", LastName "Customer Last Name", ItemID "Item Number", Description "Item Description", Quantity, Price, LastCost "Last Cost", PriceDiff "Difference Between Price and Last Cost", ExtendedDiff "Extended Price" FROM VExtendedDiff
-
Answer:
You need to add a calculation expressions and add the ORDER BY condition: SELECT OrderID "Order Number", OrderDate "Order Date", LastName "Customer Last Name", ItemID "Item Number", Description "Item Description", Quantity, Price, LastCost "Last Cost", PriceDiff "Difference Between Price and Last Cost", ExtendedDiff "Extended Price", Quantity*Price AS Profit FROM VExtendedDiff ORDER BY Profit DESC
showtime at Yahoo! Answers Visit the source
Related Q & A:
- Can I create a second filestream container on an existing SQL Server 2008 database without going offline?Best solution by Database Administrators
- Does it ever make sense to use RAM Disk to force RAM allocation for tempdb with SQL Server 2008?Best solution by Database Administrators
- How to Restrict Database for One User in SQL Server 2008 R2?Best solution by Database Administrators
- How to add primary key from multiple table as a foreign key in a table in sql server 2008?Best solution by stackoverflow.com
- How to enable remote connections in SQL Server 2008?Best solution by Server Fault
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.