postgresql - How to sum rows in groups then filter rows based on the sum -


i want find sum , count of positive values in table grouped type column. interested in cases sum >= 10 , count >= 2

for example,

type  |  value  ------+-------     | 10 b     | 5 c     | 7 b     | 5 c     | 6 c     | -1 d     | 3 d     | 4 

i want result

type  | sum  | count ------+------+------ b     | 10   | 2 c     | 13   | 2 

there should not row a because count 1. there should not row d because sum 7. negative value should ignored.

i think answer should like:

select type, sum(value) sum, count(value) count my_table value > 0 group type having sum >= 10 , count >= 2 

however not sure how correctly combine of relevant conditions.

select type, sum(value) sum, count(type) count my_table value > 0 group type having sum(value) >= 10 , count(type) >= 2 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -