Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2005
    Location
    Kuala Lumpur, MY
    Posts
    108

    Unanswered: select statement query

    hie all, i have a select statement which looks like this

    Code:
    select dealer_id, sum(sum_f1) sum_f1, sum(sum_f2) sum_f2, sum(count_f1) count_f1, sum(count_f2) count_f2
    from f01_dealer_balance_to_user
    where (sum_f1 <> sum_f2 or count_f1 <> count_f2)and (TO_DATE(reload_date,'DD-MM-RR')  >=  '24-MAR-06'
    AND TO_DATE(reload_date,'DD-MM-RR')  <=  '24-MAR-06')
    group by dealer_id
    im having problem with this line which is bolded, it is matching line by line based on dates which i dont want, what i want is to sum all together and only then exclude the ones which are not matching and i think it should look something like this


    Code:
    select dealer_id, sum(sum_f1) sum_f1, sum(sum_f2) sum_f2, sum(count_f1) count_f1, sum(count_f2) count_f2
    from f01_dealer_balance_to_user
    and (TO_DATE(reload_date,'DD-MM-RR')  >=  '24-MAR-06'
    AND TO_DATE(reload_date,'DD-MM-RR')  <=  '24-MAR-06')
    group by dealer_id
    where (sum_f1 <> sum_f2 or count_f1 <> count_f2)
    anyone could help ?

  2. #2
    Join Date
    Aug 2004
    Location
    France
    Posts
    754
    What you need is a HAVING clause :

    Code:
    select dealer_id, sum(sum_f1) sum_f1, sum(sum_f2) sum_f2, sum(count_f1) count_f1, sum(count_f2) count_f2
    from f01_dealer_balance_to_user
    where (TO_DATE(reload_date,'DD-MM-RR')  >=  '24-MAR-06'
    and TO_DATE(reload_date,'DD-MM-RR')  <=  '24-MAR-06')
    group by dealer_id
    having (sum_f1 <> sum_f2 or count_f1 <> count_f2)
    HTH & Regards,

    rbaraer
    ORA-000TK : No bind variable detected... Shared Pool Alert code 5 - Nuclear query ready .

Posting Permissions

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