Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Posts
    18

    Unanswered: 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.

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    .......
    .......

    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

  3. #3
    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??

  4. #4
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •