I have this table (model - not table in SQL, all keys are joined to a real table but I need to count keys which exist in this model.)
key1 key2 key 3
v1 d1 t1
v2 d2 t1
v3 d1 t4
v1 d3 t8
v1 d2 t4
The result needs to return
key1 v1 3
key1 v2 1
key1 v3 1
key2 d1 2
fiddle for test http://sqlfiddle.com/#!9/c102f
I can't select all the keys one by one, because the number of keys = 79 and rows num = 1 115 260
one by one select process takes 2 mins