Results 1 to 3 of 3

Thread: SQl Help

  1. #1
    Join Date
    Dec 2003
    Location
    Louisville
    Posts
    1

    Angry Unanswered: SQl Help

    Can the following sql code be written with a DECODE and SUM FUNCTION?

    SELECT COUNT(*)FROM TABLENAME WHERE
    LOAD_NR = FLY_NR
    AND LOAD_S_CODE NOT IN ('E', 'C', 'X')
    AND LOAD_D_CODE NOT IN ('E','C', 'X')
    AND EQUIP_NR IS NOT NULL;

    I WAS THINKING OF SOMETHING LIKE

    SUM(DECODE(LOAD_NR,FLY_NR,1...

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    no

  3. #3
    Join Date
    Dec 2003
    Location
    Noida, India.
    Posts
    171

    Re: SQl Help

    It can be, using nested decodes ... But its complexity would make it difficult to maintain it:

    -- Indented for better understanding:
    select sum(decode(LOAD_NR,FLY_NR,
    decode(LOAD_S_CODE,'E',0,
    'C',0,
    'X',0,
    decode(LOAD_D_CODE,'E',0,
    'C',0,
    'X',0,
    decode(EQUIP_NR,null,0,1)))
    ,0))
    from TABLENAME ;

    -- Without indentation
    select sum(decode(LOAD_NR,FLY_NR, decode(LOAD_S_CODE,'E',0,'C',0,'X',0,decode(LOAD_D _CODE,'E',0,'C',0,'X',0,decode(EQUIP_NR,null,0,1)) ),0))
    from TABLENAME ;




    Originally posted by rhopkins
    Can the following sql code be written with a DECODE and SUM FUNCTION?

    SELECT COUNT(*)FROM TABLENAME WHERE
    LOAD_NR = FLY_NR
    AND LOAD_S_CODE NOT IN ('E', 'C', 'X')
    AND LOAD_D_CODE NOT IN ('E','C', 'X')
    AND EQUIP_NR IS NOT NULL;

    I WAS THINKING OF SOMETHING LIKE

    SUM(DECODE(LOAD_NR,FLY_NR,1...
    Oracle can do wonders !

Posting Permissions

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