find out the number of times an ANI has called in the service using sql queries

StackOverflow https://stackoverflow.com/questions/22684674

  •  22-06-2023
  •  | 
  •  

문제

i have a table with two columns SERVICE and ANI. let's say like the one below

SERVICE      ANI
_________________
CRIC        54321
MOVIES      87945 
FITNESS     64587
MUSIC       54321
CRIC        54321
FITNESS     87945
FITNESS     87945
MUSIC       87945
MOVIES      54321
MUSIC       64587
CRIC        64587
FITNES      54321

(ANI is Phone number) and I have find out to that how many times a single ANI calls for a particular service. i have to group by ANI and service and find out the count of each ANI for each SERVICE. output should be something like

(SERVICE)     (ANI)     (ANI_COUNT)
CRIC     54321       2
MUSIC    54321        1
MOVIES   87945        1
FITNESS  87945         2

and so on. it means that the ANI 54321 has called twice for CRIC service and once for music. ANI 87945 has called once for MOVIES and twice for FITNESS

can anybody guide me how can i do it?

도움이 되었습니까?

해결책

If I understand the question correctly, you can try to group by SERVICE and ANI as follow, to achieve output like the 2nd code block in this question :

SELECT
    SERVICE, ANI, COUNT(*) AS 'ANI_COUNT'
FROM
    MyTable
GROUP BY SERVICE, ANI

[Fiddle Demo]

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top