mysql compare 2 rows same table
mysql compare 2 rows same table
I am trying to compare 2 rows and display the same ones.I did browse but was not able to find the right solution.
Table A
Count status Division
20 A 1
30 B 2
10 c 1
12 z 1
From the above table I want to display whose division is same.
Count status Division
20 A 1
10 c 1
12 z 1
SELECT * FROM TableName WHERE division=_____-Display information where division = something OR SELECT COUNT(*), division FROM TableName GROUP BY division- Display number of records for each division– David Starkey
Mar 25 '13 at 22:28
SELECT * FROM TableName WHERE division=_____
SELECT COUNT(*), division FROM TableName GROUP BY division
3 Answers
3
Try this
Select * from TableA
Group By Division
Having Count(*) > 1
Select * from TableA
Group By Division
having Count(*) = 1
You should flesh out your answer a bit.
– joce
Mar 25 '13 at 23:00
Here i used case statement , it worked for me
select CompanyCode ,'Commission Pec', Year
,sum(case when CommissionType='Commission Recevied' then JAN else 0 end)/sum(case when CommissionType='Net Payments from WM' and isnull(JAN,0)<>0 then JAN else 1 end)
from Commission_Consolidate
group by CompanyCode,Year
end
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
Please format output. Its difficult to understand what you need
– DevelopmentIsMyPassion
Mar 25 '13 at 22:27