2016-03-21 12 views
0

Ich habe Daten von Call-Kunden gesetzt, ich will Kunde, wo er inmachen viele count() in einer Abfrage

diese meine Daten:

Phone no. - Duration In minutes - Location 

1111   3      88 
2222   4      33 
3333   4      4 
1111   7      55 
3333   9      4 
3333   7      3 

das Ergebnis der Abfrage:

phone no- Total number of records -Total duration of calls- Total of location 

1111    2       10     2 
2222    1       4     1 
3333    3       20     2 
+0

Gruppe, Anzahl, Summe usw. – jarlh

+3

Dies scheint eine grundlegende 'Gruppe by' Abfrage. Was ist das Problem? –

+0

Vielen Dank für die Hilfe ... –

Antwort

0

Diese fast ähnlich ist Antwort auf fthiella. Versuchen Sie, wie diese

select PhoneNo, 
count(*) as TotalNumberOfRecords, 
sum(DurationInMinutes) as TotalDurationOfCalls, 
count(distinct location) as TotalOfLocations from yourtablename 
group by PhoneNo 
0

können Sie verwenden, um eine GROUP BY-Abfrage mit grundlegenden aggregiert Funktionen wie COUNT(), SUM() und COUNT (DISTINCT) wie folgt aus:

select phone_no, count(*), sum(duration), count(distinct location) 
from tablename 
group by phone_no 
0

Antwort auf Ihre Frage

ist
select Phone no,count(Duration In minutes),sum(Duration In minutes),count(distinct Location) from Tablename group by Phone no order by Phone no; 
0

ich temporäre Tabelle für die Prüfung gemacht haben, und es gibt gleiche Ausgabe wie Sie erwähnen. schauen folgende Abfrage:

declare @TEMP table (phone_no int, duration int, location int) 
insert into @temp values(1111,3,88),(2222,4,33),(3333,4,4),(1111,7,55),(3333,9,4),(3333,7,3) 

select phone_no, count(*), sum(duration), count(distinct location) 
from @TEMP 
group by phone_no 

Sie gerade diese Abfrage betrachten können:

select phone_no, count(*), sum(duration), count(distinct location) 
from @TEMP 
group by phone_no