SQL query: Get result from row3 and row6 only sometime row1 and 10 only

305 pts.
Tags:
SQL
SQL Query
PRIMARY KEY (A/C. NO.) ALSO EXISTS IN TABLE2 AND TABLE 3
TABLE1 TABLE2 TABLE3 TABLE3
a/c. no. Consum demand dues
65138546 2500 193 193
65138546 3100 696 696
65138546 3500 700 700
65138546 4000 763 763
65138546 6000 867 867
65138546 7000 1125 1888
65138546 8000 1281 1281
65138546 9000 1594 1594
65138546 10000 1783 1783
65138546 11000 1999 1999
65138546 12000 2013 2013
65138546 13000 2041 2041
65138546 14000 2275 2275

Answer Wiki

Thanks. We'll let you know when a new response is added.

Seems like a fairly simple class assignment. What code have you tried? What were your results? We can help you fix your problem, we just won’t do it for you as it takes away your learning be doing it your self. In you select statement use the where clause and use a constant value from rows 3 & 6 or 1 & 10 what ever is needed. Post your code if you still need help

Discuss This Question: 7  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • 235235235
    That is why I post the table. I could not understand how I prepare query using 'select' statement. Actually, I want the demand before 7000 consumption and after 7000 consumption.
    305 pointsBadges:
    report
  • 235235235
    Mr. carl has been very helpful. Please help to make query of above mentioned table.
    305 pointsBadges:
    report
  • ToddN2000
    If you are dealing with unknown values but still want a set number of rows returned the use the SELECT TOP? Post your code and we will be glad to help you understand it better.
    95,450 pointsBadges:
    report
  • 235235235
    SELECT  A.A/C.NO, B.CONSUM, C.DEMAND,C.DEMAND
    FROM BILHST A, CONSUMPTION B,BILMST C
    WHERE A.A/C.NO=B.A/C.NO
    AND B.A/C.NO= C.A/C.NO
    WHERE CONSUM=7000
    AND DEMAND 
    AND DEMAND 

    (HERE I WANT TO SHOW  BOTH DEMANDS BEFORE 7000 that is 867
    AND AFTER 7000  that is 1281)
    305 pointsBadges:
    report
  • 235235235
    Please reply to my above mentioned query.
    305 pointsBadges:
    report
  • ToddN2000
    What are you really selecting on the row, consumption, demand or dues? This is needed to build the WHERE portion of your SELECT statement. For getting data like the rows 1 and 10 you could use the MIN and MAX features. In your sample code I don't see a JOIN..
    95,450 pointsBadges:
    report
  • 235235235
    I want to select demand before 7000 consumption i.e.867 and after 7000 demand i.e.1125 pl.
    305 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: