If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Simple SQL query question.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-29-05, 13:45
jasoberai jasoberai is offline
Registered User
 
Join Date: Jan 2005
Posts: 18
Simple SQL query question.

Hi Friends,
I have a simple query like this:
Select col1,col2,.......,currency,amount,...........coln
from ....
where ....
group by ....

I use the currency and amount columns for calculating data for other columns.I have 2 questions.First,is there a way by which I just can use the currency and amount data and not display them.I am able to remove all the data,but the column header still shows up.
Second,right now I am displaying these two columns,but I need that group by clause should not take currency column into consideration when grouping data.Because due to this column,my data gets replicated.
Reply With Quote
  #2 (permalink)  
Old 01-29-05, 13:52
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
.......
.......

As you can see, ...... is of little use to you in my answer above. The same holds true in your question. Please post the exact SQL statement and explain what you want the output to look like.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 01-29-05, 14:25
jasoberai jasoberai is offline
Registered User
 
Join Date: Jan 2005
Posts: 18
select
tr.id,ftd.currency as USD sum(ftd.amount) as AMTUSD,'' as CAD,'' as AMTCAD,
ft.Currency as CUsd,ft.amount as AUSD,''as Ccad,''as Acad

from
finaltable as ft,
final_table_details as ftd,
table_results as tr,
table as t

where
tr.id=t.id and
tr.datetime=ftd.datetime and
tr.id=ftd.t_id and
ftd.t_id=ft.t_id and
ftd.t_date=ft.t_date

group by
tr.id,tr.datetime,t.name,ftd.currency,ft.currency, ft.amount.


After some programming,I am getting results as :

ID USD AMTUSD CAD AMTCAD CUSD AUSD CCAD ACAD

1 USD 10 USD 100

1 CAD 20 CAD 200



I want that if ID is same,results should be like:


ID USD AMTUSD CAD AMTCAD CUSD AUSD CCAD ACAD

1 USD 10 CAD 20 USD 100 CAD 200



Can you please help me now??
Reply With Quote
  #4 (permalink)  
Old 01-29-05, 14:31
jasoberai jasoberai is offline
Registered User
 
Join Date: Jan 2005
Posts: 18
I AM SORRY,the table format got messed up,just take into account that for the first table,usd currency goes under USD,usd amount goes under AMTUSD,cad currency goes under CAD and amount under AMTCAD.This is another idea of the first table

ID--------- 1 , 1
USD------- USD
AMTUSD--- 10,
CAD------- CAD
AMTCAD--- ,20
CUSD------ USD
AUSD------ 100
CCAD------ ,CAD
ACAD------ ,200
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On