Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Count Help please basic SQL

Author  Topic 

emdavies82
Starting Member

2 Posts

Posted - 2011-10-27 : 04:48:19
Hi,
Im trying to teach my self SQL query. So sorry if this sounds stupid.
I want to find out how many people are living at the same address so have done this.

SELECT COUNT(Address_Line_1) AS Expr1, Address_Line_1
FROM Pers_Static_Personnel_History
GROUP BY Address_Line_1
HAVING (COUNT(Address_Line_1) > 1)
ORDER BY COUNT(Address_Line_1)

However its returning resutls such as 5 live at flat 1. This could not be the same address so I need to add in the post code.
How do I change this so It will look at the Adress line 1 field and the postcode field then count how many of theose two records together there are?

Thanks for your help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-27 : 04:49:56
[code]
SELECT COUNT(1) AS Expr1, Address_Line_1,PostCode
FROM Pers_Static_Personnel_History
GROUP BY Address_Line_1,PostCode
HAVING (COUNT(1) > 1)
ORDER BY COUNT(1)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -