ms sql pivot count

  • I have student table store in student contact number ,parent contact number , name address ,etc. and need to pivot parent contact number and student contact number separately and need to give where condition as where Parent_Mobile_No like '9477%' and where Parent_Mobile_No like '9471%'

  • chamindak (7/1/2014)


    I have student table store in student contact number ,parent contact number , name address ,etc. and need to pivot parent contact number and student contact number separately and need to give where condition as where Parent_Mobile_No like '9477%' and where Parent_Mobile_No like '9471%'

    That is amazing.

    Is there also a question?

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • SELECT

    CASE

    WHEN Parent_Mobile_No LIKE '9477%' THEN 'Dialog077'

    WHEN Parent_Mobile_No LIKE '9476%' THEN 'Dialog076'

    WHEN Parent_Mobile_No LIKE '9471%' THEN 'Mobitel'

    WHEN Parent_Mobile_No LIKE '9472%' THEN 'Etisalat'

    WHEN Parent_Mobile_No LIKE '9475%' THEN 'Airtel'

    WHEN Parent_Mobile_No LIKE '9478%' THEN 'Hutch'

    END AS Mobile_Operator

    , COUNT(*) AS Parent_Mobile_No

    FROM mststudent

    where ins_id ='0007'

    GROUP BY

    CASE

    WHEN Parent_Mobile_No LIKE '9477%' THEN 'Dialog077'

    WHEN Parent_Mobile_No LIKE '9476%' THEN 'Dialog076'

    WHEN Parent_Mobile_No LIKE '9471%' THEN 'Mobitel'

    WHEN Parent_Mobile_No LIKE '9472%' THEN 'Etisalat'

    WHEN Parent_Mobile_No LIKE '9475%' THEN 'Airtel'

    WHEN Parent_Mobile_No LIKE '9478%' THEN 'Hutch'

    END

  • please give example input and desired output

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply