473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Help with Order By AND ROWNUM by a student

I've tried several scripts and NONE of them have worked. I need to apply the Order By first, then limit to the top 10 Rows. Here are two I've tried, with both i'm getting a "command not properly ended" message:


--Question 8c 4 columns from Invoices table with alias' and two calculated columns and filter and sort with ROWNUM

Expand|Select|Wrap|Line Numbers
  1. SELECT  invoice_number AS "Number", invoice_total AS "Total", payment_total + credit_total AS "Credits", invoice_total - (payment_total + credit_total) AS "Balance Due"
  2. FROM  invoices
  3. WHERE invoice_total - (payment_total + credit_total) > 500
  4. ORDER BY 4 DESC
  5.   (SELECT *
  6.   WHERE ROWNUM = 10)

Expand|Select|Wrap|Line Numbers
  1. SELECT  invoice_number AS "Number", invoice_total AS "Total", payment_total + credit_total AS "Credits", invoice_total - (payment_total + credit_total) AS "Balance Due"
  2. FROM  invoices
  3. WHERE invoice_total - (payment_total + credit_total) > 500 
  4.       ( SELECT * from invoices
  5.       ORDER BY invoice_total - (payment_total + credit_total) DESC
  6.       );
  7. WHERE ROWNUM = 10;
Oct 25 '12 #1
2 1798
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

The correct syntax is this:
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM (
  3.    SELECT *
  4.    FROM someTable
  5.    ORDER BY someField
  6. )
  7. WHERE rownum <= 10;
Oct 25 '12 #2
WOW! You are amazing.....that answer worked like a charm....don't know why my book doesn't lay it out in those terms....
Sorry about the incorrect format, I will get it right next time.
Thanks!
Oct 25 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Muzamil | last post by:
Hi I want a simple select query on a column-name (smalldatetime) with values dislayed in desc order with null values FIRST. i.e. Select orderdate from orders order by ( null values first...
13
by: Joe Black | last post by:
Just to inform you guys that i have only like 2 weeks that i took my first classes in c++, and my proffesor now is asking me to solve this problem: /// Using a function create a Win32 Console...
3
by: Paul T. Rong | last post by:
Hello there, I am making a report using codes bellow (a part of): ------------------------------- Select Case Forms!!TopBoard Dim strGetSQL As String
3
by: John | last post by:
Hi there - if anyone has a few spare minutes I could really do with some help please. I'm a student and have been given an exercise using MS Access to design a simple database for a fictional...
26
by: Bail | last post by:
I will have a exam on the oncoming friday, my professor told us that it will base upon this program. i am having troubles understanding this program, for example what if i want to add all the...
48
by: phillip.s.powell | last post by:
MySQL 3.23.58 - 4.0.17 (yep, several database server instances, don't ask) I have database Spring with table Students I have database Summer with table Students I am tasked to produce a...
28
by: Nutkin | last post by:
Basicly i have to make a program that calculates the distance between x and y points in 2d space. the code basicly goes like this 1. User says how many points they have (max of 10) 2. User...
5
by: thehonos | last post by:
I am trying to help a former student. He needs to resolve this problem in javascript and I do not teach javacript and I am lost.. Can any one help?!?!?!? Write JavaScript to solve the following...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.