Home » SQL & PL/SQL » SQL & PL/SQL » Help Needed Regarding the following Query
Help Needed Regarding the following Query [message #184984] Sat, 29 July 2006 09:37 Go to next message
vivekanandaan
Messages: 8
Registered: July 2006
Junior Member
Hi,

Attached is my requirement.

Kindly help me out.

Regards

R.Vivek
  • Attachment: Help_Me.doc
    (Size: 29.00KB, Downloaded 436 times)
Re: Help Needed Regarding the following Query [message #185013 is a reply to message #184984] Sun, 30 July 2006 00:54 Go to previous messageGo to next message
Frank
Messages: 7901
Registered: March 2000
Senior Member
Use decode to select the p- and r-amounts depending on the value of transaction.

Try this yourself first as this is very basic SQL. If you are stuck, come back and show us what you did.

Next time, please post your question directly in your post; not as an attachment.
You can read in the first couple of posts in the forum how to format your text. (You can use [code] and [/code] tags around your code part)
Re: Help Needed Regarding the following Query [message #185017 is a reply to message #185013] Sun, 30 July 2006 01:42 Go to previous messageGo to next message
vivekanandaan
Messages: 8
Registered: July 2006
Junior Member
Hi Frank,

SELECT BILL_NO,CUST_NO,DECODE(TYPE,'P',AMT,0) P_AMT,DECODE(TYPE,'R',AMT,0) R_AMT,AMT
FROM BILL_ADD;

The above query works fine.

Thanks a lot.

Regards

R.Vivek
Re: Help Needed Regarding the following Query [message #185025 is a reply to message #184984] Sun, 30 July 2006 03:23 Go to previous messageGo to next message
vivekanandaan
Messages: 8
Registered: July 2006
Junior Member
Hi Frank,

Is there any other way to recreate the same result.

i.e using any sub-queries.

I was asked in an interview ?

Regards

R.Vivek
Re: Help Needed Regarding the following Query [message #185029 is a reply to message #184984] Sun, 30 July 2006 05:15 Go to previous messageGo to next message
vivekanandaan
Messages: 8
Registered: July 2006
Junior Member
Hi to all,

Could somebody help me.

Regards

R.Vivek
Re: Help Needed Regarding the following Query [message #185047 is a reply to message #185029] Sun, 30 July 2006 11:46 Go to previous messageGo to next message
Frank
Messages: 7901
Registered: March 2000
Senior Member
Well, wrap all of your query in a "select * from" and you got a solution with a subquery.

I just can't understand why these interviewers keep on asking such idiotic and totally irrelevant questions. Your query looks just fine to me!
Re: Help Needed Regarding the following Query [message #185092 is a reply to message #184984] Mon, 31 July 2006 00:11 Go to previous messageGo to next message
vivekanandaan
Messages: 8
Registered: July 2006
Junior Member
Hi to all,

I got it.

Below is the query :

SELECT BILLNO,CNO,AMT AS P_AMT, 0 as R_AMT,AMT
FROM DAILYBILL where type='Purchase'
UNION ALL
SELECT BILLNO,CNO,0 AS P_AMT, AMT as R_AMT,AMT
FROM DAILYBILL where type='Settlement';

Thanks & Regards

R.Vivekanandaan
Re: Help Needed Regarding the following Query [message #185141 is a reply to message #185092] Mon, 31 July 2006 03:17 Go to previous message
Frank
Messages: 7901
Registered: March 2000
Senior Member
And where is your subquery?
Previous Topic: Need help in comparison of date...
Next Topic: Delete duplicate rows
Goto Forum:
  


Current Time: Tue Dec 03 14:58:35 CST 2024