Ask a Question related to ASP Database, Design and Development.
-
MDW #1
Using COUNT() In WHERE Clause
I know it's verboten. However, I'm not sure how else is the best way to do this.
I've got two tables, tblReferrers and tblReferrals. I'm creating an ASP report to show who among the referrers hasn't met certain miniumum requirements (e.g., they should have a certain number of referrals). The two tables are related by a field called ReferrerID. My result set needs to be who, on tblReferrers, appears in tblReferrers less than a given number - something that COUNT() would be ideal for.
I'm sure I could accomplish this with looping, but I'd like to execute only one SQL statement to get my result set. Any ideas?
MDW Guest
-
Using IN in a WHERE clause
I'm trying to use IN in a WHERE clause as follows: idx_res.city IN ('#session.s_city#') The value of session.s_city is 'highlands ranch, lone... -
CF MX 6 WHERE Clause
Hi everyone! I keep getting the following error when I submit an update form for processing Macromedia] Too few parameters. Expected 1. The error... -
Help - problem with sql where clause
Someone help me trace the error with the WhereClause variable(or how to structure it). The database is in Ms Access Part of the program is listed... -
connect by clause
i have written this query on test database works fine but when we transfered both tables and the query to production we are getting two different... -
Using variable in From clause
I want to write a T-Sql script that will cycle through all of the tables in a database and write the number of records in each table. I have the... -
John Scragg #2
RE: Using COUNT() In WHERE Clause
I think what you are looking for here is the HAVING keyword. COUNT is an aggregate, so you will have to work out your GROUP BY clause, but something like this example should do it.
SELECT a.ReferrerID, a.Blah, COUNT(b.ReferrerID)
FROM tblReferrers a INNER JOIN tblReferrals b ON a.ReferrerID = b.ReferrerID
GROUP BY a.ReferrerID, a.Blah
HAVING COUNT(b.ReffererID) > X
Hope that is helpful,
John
----- MDW wrote: -----
I know it's verboten. However, I'm not sure how else is the best way to do this.
I've got two tables, tblReferrers and tblReferrals. I'm creating an ASP report to show who among the referrers hasn't met certain miniumum requirements (e.g., they should have a certain number of referrals). The two tables are related by a field called ReferrerID. My result set needs to be who, on tblReferrers, appears in tblReferrers less than a given number - something that COUNT() would be ideal for.
I'm sure I could accomplish this with looping, but I'd like to execute only one SQL statement to get my result set. Any ideas?
John Scragg Guest



Reply With Quote

