I have a PostgreSQL table like this:
CREATE TABLE foo (man_id, subgroup, power, grp)
AS VALUES
( 1, 'Sub_A', 1, 'Group_A' ),
( 2, 'Sub_B', -1, 'Group_A' ),
( 3, 'Sub_A', -1, 'Group_B' ),
( 4, 'Sub_B', 1, 'Group_B' ),
( 5, 'Sub_A', -1, 'Group_A' ),
( 6, 'Sub_B', 1, 'Group_A' ),
( 7, 'Sub_A', -1, 'Group_B' ),
( 8, 'Sub_B', 1, 'Group_B' );
The power calculation works like this:
Total Power of Subgroup Sub_A in the grp Group_A is (1 + (-1) ) = 0
Total Power of Subgroup Sub_B in the grp Group_A is ((-1) + 1 ) = 0
Total Power of Subgroup Sub_A in the grp Group_B is ((-1) + (-1) ) = -2
Total Power of Subgroup Sub_B in the grp Group_B is (1 + 1 ) = 2
So the power of Sub_A in the Group_A is not equal to power of Sub_A in the Group_B
So the power of Sub_B in the Group_A is not equal to power of Sub_B in the Group_B
I want to query the database with a subgroup
name. If for a same subgroup
name power is equal across all the other grp
names, then it will return True
, else False
.
As an example, sub_A
and sub_B
both will return False
. What would be the recommended way to do this?
I want something like:
SELECT * FROM foo (solution query will be added)
WHERE subgroup = 'sub_A'
And it returns False
.