How to perform statistical fashion in SQL?

1

Working for a telephone charging system company, all connections generated by the PBX are billed by the system and stored in a table called 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 = connection value.

To make a summation, for example, I already have the following query working:

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

Now, I would like to know how this same query would look to calculate the statistical fashion, that is, the value that most appeared in the registers of the cadcha table.

    
asked by anonymous 15.12.2015 / 15:18

1 answer

2

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

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