Link to home
Start Free TrialLog in
Avatar of Wilder1626
Wilder1626Flag for Canada

asked on

Oracle - Query to count NO value per row

Hello all

I have this SQL where i would like to count the number of NO value per row.

It would add an extract column to the query called "ISSUE" and put the count of NO per row.

ex:
User generated image
Thanks again

Full code:
SELECT DISTINCT LOCATION.ID,
    LOCATION.SCNALIAS,
    CASE 
        WHEN LOCATION.SCNALIAS IS NOT NULL
            THEN '-'
        ELSE 'NO'
        END SCNALIAS_SET,
            NVL((
                SELECT '-'
                FROM TMMGR.FP_VENDOR_INFO
                WHERE LOCATION.SCNALIAS = FP_VENDOR_INFO.VENDOR_NBR
                    AND ROWNUM = 1
                ), 'NO') FREIGHT_PAY_MATCH,            
    NVL((
            SELECT '-'
            FROM TL_RATE TLR,
                TL_RATE_DETAIL TRD,
                LANE_RATE_NETWORK LRN
            WHERE TLR.CARRIER_ID = TRD.CARRIER_ID(+)
                AND TLR.LANE_ID = TRD.LANE_ID(+)
                AND TLR.TARIFF_CLASS_ID = TRD.TARIFF_CLASS_ID(+)
                AND TLR.EFFECTIVE = TRD.EFFECTIVE(+)
                AND TLR.LANE_ID = LRN.ID
                AND TLR.CARRIER_ID = 'CUSTOMER'
                AND LRN.FROM_KEY_NUM = 6
                AND LRN.FROM_LOW_KEY_VALUE (+) = LOCATION.ID
                AND TLR.EXPIRATION > TO_DATE(TO_CHAR(SYSDATE, 'YYYYMMDD'), 'YYYYMMDD')
                AND ROWNUM = 1
                ), 'NO') VENDOR_RATE_SET                
FROM TMMGR.LOCATION
WHERE (
        SUBSTR(LOCATION.ID, 6, 1) BETWEEN 'A'
            AND ('Z')
        AND SUBSTR(LOCATION.ID, 3, 1) BETWEEN '0'
            AND ('9')
        )
ORDER BY LOCATION.SCNALIAS ASC;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Wilder1626

ASKER

Ho again.

Many thanks, this is great.