Reputation: 69
I want to compare columns in a table.
I have something like this:
id n_emp paid
1 1 0
2 1 0
3 1 0
4 2 1
5 2 0
6 2 0
7 3 1
8 3 1
And I want this result:
n_emp paid
1 0
2 0
3 1
In other words, if all paid it should return 1, if all not paid it should return 0.
Can anybody help, please?
Upvotes: 0
Views: 62
Reputation: 33273
MIN(paid)
will be 0 if one or more rows have 0.
SELECT n_emp, MIN(paid) FROM myTable GROUP BY n_emp
Upvotes: 2