Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Counting Distinct

Status
Not open for further replies.

calleng

IS-IT--Management
Jan 13, 2005
2
0
0
US
Could someone tell me if it is possible to do what I am trying to do.

3 fields in a table - DateTime, LocalAddr, and TargetAddr

I am trying to output to a second table that would contain

LocalAddr with a count of the number of

DISTINCT LocalAddr

Example output:

LocalAddr Number
xxx.xxx.xxx.001 50
xxx.xxx.xxx.002 102
xxx.xxx.xxx.003 78
 
what is the sample of data in the original table.

Based on what I can see you could just do
SELECT DISCTINCT (LocalAddr), COUNT(*)
FROM MyTable
Group By LocalAddr


"I'm living so far beyond my income that we may almost be said to be living apart
 
SELECT LocalAddr, COUNT(*) AS TOTALCOUNT FROM yourtable GROUP BY LocalAddr

-L

 
Just add the INSERT command to hmckillop's SELECT.

INSERT INTO secondtbl
SELECT DISTINCT LocalAddr, COUNT(LocalAddr)
FROM firsttbl
GROUP BY LocalAddr

-SQLBill

Posting advice: FAQ481-4875
 
Thanks - that is exactly what I needed.
 
DISTINCT is not needed in this. COUNT(localaddr) with the group by localaddr is the key. If you want to get a listing based on localaddr count add HAVING

SELECT LocalAddr, COUNT(LocalAddr)
FROM firsttbl
GROUP BY LocalAddr HAVING COUNT(LocalAddr) > 3


Attitude is Everything
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top