0
$\begingroup$

I have a data file like this:

User  Item
Ram   Dog
sam   Dog
Ram   wolf
max   lion
zed   fox
sam   cat
zed   cat
max   dog
max   cat

I want to check for conflict: the conflict is like people who have dogs breeds cant have cats breeds the matrix is given like this

animal  Dog Fox Wolf cat lion
Dog     S   Y    Y   N   N
fox     Y   S    Y   N   N
wolf    Y   Y    S   N   N
cat     N   N    N   S   Y
lion    N   N    N   Y   N

I want output like if I run a query/button i should get list of people who have Conflicting breeds based on the conflict matrix above

$\endgroup$
0
$\begingroup$

You can use pivot method. it works in SQL like this.

SELECT User , 
CASE 
    WHEN Item = 'Dog' THEN 1
    ELSE 0
END AS DOG,
CASE 
    WHEN Item = 'Fox' THEN 1
    ELSE 0
END AS FOX,
CASE 
    WHEN Item = 'Wolf' THEN 1
    ELSE 0
END AS WOLF,
CASE 
    WHEN Item = 'cat' THEN 1
    ELSE 0
END AS CAT, 
CASE 
    WHEN Item = 'lion' THEN 1
    ELSE 0
END AS LION

FROM yourTable

afterwords, you can cheak your conditions.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.