1

I have a little problem, my query look like this

select count(A.toto) from B inner join C on B.tata = C.tata inner join A on C.tutu = A.tutu group by A.toto, A.zaza, A.zozo; 

and my result look like this :

1 2 1 6 7 4 1 1 1 

But I want only the number of rows, for this example, the value that I would like to have is 9. But I don't know how I can have this value... Thank you in advance !!

1 Answer 1

2

You can use count(distinct). Unfortunately, Oracle doesn't support count(distinct) with multiple arguments, so a typical method is just to concatenate the value together:

select count(distinct A.toto || ':' || A.zaza || ':' || A.zozo) from B inner join C on B.tata = C.tata inner join A on C.tutu = A.tutu; 

This assumes that. the column values don't have the separator character (or at least in such a way that the concatenation is the same for rows with different key values).

An alternative method is to use a subquery:

select count(*) from (select 1 from B inner join C on B.tata = C.tata inner join A on C.tutu = A.tutu group by A.toto, A.zaza, A.zozo ) abc 
Sign up to request clarification or add additional context in comments.

1 Comment

I think the first query works wth nulls as well since Oracle convert nulls to '' (empty string) while concatenating.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.