I have a table like these:
STATE code company rate
----------------------------------
TX SD 1 0.5
TX SD 2 0.5
TX SD 3 0.7
TX SD 4 0.5
..........
I need to verify that is the rate same under the same state and same code.
I consider to join the table by itself and get the rate 1 and rate2 , then can use case when to compare the two columns
Something like this:
CASE WHEN COLUMN1 = COLUMN2 THEN '1' ELSE '0' END AS MyDesiredResult
I do not know does it work? How can I can join the table?
Basically, I need a report to see if the rate is different under the same state and same code.
thanks
this will show you the offending state/code combinations:
You can process further to find how many rows each rate have. for example using a CTE, but I left it as an exercise for the reader.