Question

So I am trying to create a query that returns account numbers that are associated with more than one account.

When I run the code

SELECT accountNumber
FROM tbl1
WHERE LabelId = 328

I get the following result:

601209.1
601212.1
601216.1
624601.1
624601.2
624601.3
624601.4
624861.1
624861.2
624861.3
624861.4
624961.1
624961.2
624961.3
624961.4
624962.1
624962.2
624962.3
624962.4
624962.5
624963.1
624963.2
624963.3
624963.4
624963.5
624963.6
624963.7
624963.8
624963.9

So here we can see that account number 624601, 624921, 624861, 624961, 624962, and 624963 all have more than one account associated with them. In order to fix this I tried this query:

SELECT FLOOR(accountNumber) AS [Account Number]
FROM tbl1
WHERE LabelId = 328

Which partly does what I need it to do, where it shows me just the account numbers, where I am getting stuck is counting the accounts that show up more than 2 times.

Thanks, F

Was it helpful?

Solution

You could use Having (http://en.wikipedia.org/wiki/Having_(SQL))

SELECT FLOOR(accountNumber) AS [Account Number]
FROM tblClientAccount
WHERE PrivateLabelSeqId = 328
GROUP BY floor(accountNumber)
Having Count(0) > 1

OTHER TIPS

SELECT FLOOR(accountNumber) AS [Account Number]
FROM tblClientAccount
WHERE PrivateLabelSeqId = 328
GROUP BY FLOOR(accountNumber)
HAVING COUNT(FLOOR(accountNumber)) > 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top