How to perform statistical fashion in SQL?

Asked

Viewed 1,551 times

1

I work for a telephone charging system company, all calls generated by the central (PABX) are charged by the system and stored in a call table cadcha.

cadcha
------------------------------------------
nreg   | telefone | ramaldestino | teldata    | telpretot
1000     35420000   6050           03/08/2015   2,50
1001     35428790   6050           03/08/2015   1,20
1002     33590000   6050           03/08/2015   2,50

telpretot = link value.

To make a sum, for example, I already have the following consultation working:

SELECT SUM(telpretot)
FROM cadcha
WHERE teldata = '08/03/2015' 
AND
ramaldestino = '6050';

Now, I wonder, how would be this same query to calculate the statistical fashion, IE, the value that more appeared in the records of cadcha table.

1 answer

2


I was able to perform the calculation by grouping by value and ordering in descending order.

SELECT COUNT(telpretot) as qtde, telpretot
FROM cadcha
WHERE teldata = '08/03/2015'
GROUP BY telpretot
ORDER BY qtde DESC

Browser other questions tagged

You are not signed in. Login or sign up in order to post.