I want maximum number of votes from these 3 columns(cong, bjp and aap) with associate column name
my table is :
| Cong | BJP | AAP | Winner | Win By |
| 18515 | 72283 | 23757 | BJP | 48526 |
| 24730 | 29373 | 36863 | AAP | 7490 |
expected result:
| maxvote | Party Name |
| 72283 | BJP |
| 36863 | AAP |
| Cong | BJP | AAP | Winner | Win By |
| 18515 | 72283 | 23757 | BJP | 48526 |
| 24730 | 29373 | 36863 | AAP | 7490 |
| maxvote | Party Name |
| 72283 | BJP |
| 36863 | AAP |
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Feb 8, 2014, 4:23 AM
Amit AryaPosted Feb 7, 2014, 11:28 PM
now I want (maxvote-Win by) after doing that i will get the against party votes, I want that party name too
expected result:
VulpesPosted Feb 7, 2014, 7:12 PM
SELECT CASE WHEN Cong >= BJP AND Cong >= AAP THEN Cong
WHEN BJP >= AAP THEN BJP
ELSE AAP
END AS maxvote, Winner AS [Party Name] FROM TableName