Ask a Question related to ASP Database, Design and Development.
-
Lasse Edsvik #1
small count problem
Hello
I have this table
Player Points
A 11
B 11
C 8
D 1
and im trying to count number of "unique" Points greater than a value.
something like:
SELECT COUNT(*)+1 FROM Players WHERE Points>8
should return 2
SELECT COUNT(*)+1 FROM Players WHERE Points>1
should return 4
SELECT COUNT(*)+1 FROM Players WHERE Points>11
should return 1
Any ideas?
/Lasse
Lasse Edsvik Guest
-
count problem
Hi, I have a problem counting the occurence of a number within 3 spefic columns for one table. What I want to do is to count the number of... -
A small problem..
...which is probably very simple but i'm having a bit of trouble. i've made a flash document which has dynamic text and a set variable. then i've... -
small problem... I hope
remove the parentheis from the variable names offending code: should be put pfilenummer into member "nummer" put pfilename into member... -
Small string problem
I'm trying to extract the numerical part and the letter part of a short string. i.e. $mix = "6KL" --> $num = "6" and $let = "KL" I can't... -
small problem
Modify > Document > Dimensions -- Patrik steve32880 wrote: -
Lasse Edsvik #2
Re: small count problem
typed wrong:
SELECT COUNT(*)+1 FROM Players WHERE Points>1
should return 3
3, not 4
"Lasse Edsvik" <lasse@nospam.com> wrote in message
news:u%23FkYPJ1DHA.2328@TK2MSFTNGP10.phx.gbl...> Hello
>
> I have this table
>
> Player Points
> A 11
> B 11
> C 8
> D 1
>
>
> and im trying to count number of "unique" Points greater than a value.
>
> something like:
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>8
>
> should return 2
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>1
>
> should return 4
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>11
>
> should return 1
>
>
> Any ideas?
>
> /Lasse
>
>
Lasse Edsvik Guest
-
Ray at #3
Re: small count problem
"Lasse Edsvik" <lasse@nospam.com> wrote in message
news:u%23FkYPJ1DHA.2328@TK2MSFTNGP10.phx.gbl...Shouldn't that only return 1 if you want the number of UNIQUE points greater> Hello
>
> I have this table
>
> Player Points
> A 11
> B 11
> C 8
> D 1
>
>
> and im trying to count number of "unique" Points greater than a value.
>
> something like:
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>8
>
> should return 2
than your value? DO you want unique row counts or unique actual point
values?
I see two unique point values or three unique rows here, not 4.>
> SELECT COUNT(*)+1 FROM Players WHERE Points>1
>
> should return 4
I don't see anything greater than 11 here. What exactly are you after in>
> SELECT COUNT(*)+1 FROM Players WHERE Points>11
>
> should return 1
your queries?
Ray at work
Ray at Guest
-
Ray at #4
Re: small count problem
Please disregard my last post. I missed the "+1" part. (ashamed...)
Ray at work
"Lasse Edsvik" <lasse@nospam.com> wrote in message
news:u%23FkYPJ1DHA.2328@TK2MSFTNGP10.phx.gbl...> Hello
>
> I have this table
>
> Player Points
> A 11
> B 11
> C 8
> D 1
>
>
> and im trying to count number of "unique" Points greater than a value.
>
> something like:
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>8
>
> should return 2
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>1
>
> should return 4
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>11
>
> should return 1
>
>
> Any ideas?
>
> /Lasse
>
>
Ray at Guest
-
Ray at #5
Re: small count problem
select count(x) +1 from (select distinct points as x from players where
points > 8)
Returns: 2
select count(x) +1 from (select distinct points as x from players where
points > 1)
Returns: 3
select count(x) +1 from (select distinct points as x from players where
points > 11)
Returns: 1
Ray at work
"Lasse Edsvik" <lasse@nospam.com> wrote in message
news:u%23FkYPJ1DHA.2328@TK2MSFTNGP10.phx.gbl...> Hello
>
> I have this table
>
> Player Points
> A 11
> B 11
> C 8
> D 1
>
>
> and im trying to count number of "unique" Points greater than a value.
>
> something like:
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>8
>
> should return 2
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>1
>
> should return 4
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>11
>
> should return 1
>
>
> Any ideas?
>
> /Lasse
>
>
Ray at Guest
-
Bob Barrows #6
Re: small count problem
Lasse Edsvik wrote:
I remember from your last post that you were using Access. Is that still the> Hello
>
> I have this table
>
> Player Points
> A 11
> B 11
> C 8
> D 1
>
>
> and im trying to count number of "unique" Points greater than a value.
>
> something like:
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>8
>
> should return 2
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>1
>
> should return 4
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>11
>
> should return 1
>
>
> Any ideas?
>
> /Lasse
case? Always tell us the database and version please. For now, I'm going to
assume that it's still Access - I hope I am not wasting my time here.
Anyways, if you WERE using SQL Server, you would be in luck, because T-SQL's
COUNT function allows the use of the DISTINCT keyword, as in:
SELECT COUNT(DISTINCT Points) ...
Unfortunately, this is not supported in JetSQL. What you are going to need
to do is generate a separate virtual table containing the distinct points.
Create a query using this SQL:
SELECT DISTINCT Points FROM Players
Save it as qDistinctPoints
Then create a new query with this SQL:
SELECT COUNT(*)+1 FROM qDistinctPoints WHERE Points>8
HTH,
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows Guest
-
Lasse Edsvik #7
Re: small count problem
thank you guys
/Lasse
"Lasse Edsvik" <lasse@nospam.com> wrote in message
news:u%23FkYPJ1DHA.2328@TK2MSFTNGP10.phx.gbl...> Hello
>
> I have this table
>
> Player Points
> A 11
> B 11
> C 8
> D 1
>
>
> and im trying to count number of "unique" Points greater than a value.
>
> something like:
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>8
>
> should return 2
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>1
>
> should return 4
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>11
>
> should return 1
>
>
> Any ideas?
>
> /Lasse
>
>
Lasse Edsvik Guest
-
Aaron Bertrand [MVP] #8
Re: small count problem
> Anyways, if you WERE using SQL Server, you would be in luck, because
T-SQL'sYou could also use the GROUP BY and HAVING clause.> COUNT function allows the use of the DISTINCT keyword, as in:
> SELECT COUNT(DISTINCT Points) ...
--
Aaron Bertrand
SQL Server MVP
[url]http://www.aspfaq.com/[/url]
Aaron Bertrand [MVP] Guest
-
Bob Barrows #9
Re: small count problem
Aaron Bertrand [MVP] wrote:
I'm not sure how that would work in this case ... can you go into more>>> Anyways, if you WERE using SQL Server, you would be in luck, because
>> T-SQL's COUNT function allows the use of the DISTINCT keyword, as in:
>> SELECT COUNT(DISTINCT Points) ...
> You could also use the GROUP BY and HAVING clause.
detail?
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows Guest
-
Aaron Bertrand [MVP] #10
Re: small count problem
Sorry, I think I may have misread the question. In many cases when I see a
SELECT (DISTINCT COUNT) it is usually a candidate for using GROUP BY. In
this case, I don't think DISTINCT adds any benefit, unless the question is
worded poorly.
--
Aaron Bertrand
SQL Server MVP
[url]http://www.aspfaq.com/[/url]
"Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
news:ugh3MNK1DHA.2396@TK2MSFTNGP09.phx.gbl...> Aaron Bertrand [MVP] wrote:>> >> >> Anyways, if you WERE using SQL Server, you would be in luck, because
> >> T-SQL's COUNT function allows the use of the DISTINCT keyword, as in:
> >> SELECT COUNT(DISTINCT Points) ...
> > You could also use the GROUP BY and HAVING clause.
> I'm not sure how that would work in this case ... can you go into more
> detail?
Aaron Bertrand [MVP] Guest
-
Chris Hohmann #11
Re: small count problem
"Lasse Edsvik" <lasse@nospam.com> wrote in message
news:u%23FkYPJ1DHA.2328@TK2MSFTNGP10.phx.gbl...Assuming Players.Player is unique, here's an alternative to the> Hello
>
> I have this table
>
> Player Points
> A 11
> B 11
> C 8
> D 1
>
>
> and im trying to count number of "unique" Points greater than a value.
>
> something like:
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>8
>
> should return 2
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>1
>
> should return 4
>
> SELECT COUNT(*)+1 FROM Players WHERE Points>11
>
> should return 1
>
>
> Any ideas?
>
> /Lasse
>
>
subquery-based solutions offered thus far.
PARAMETERS
prmPoints INT
;
SELECT
COUNT(*) + 1
FROM
Players AS P1 LEFT JOIN
Players AS P2 ON
P1.Points = P2.Points AND
P1.Player > P2.Player
WHERE
P2.Player IS NULL AND
P1.Points > prmPoints
HTH
-Chris Hohmann
Chris Hohmann Guest
-
Lasse Edsvik #12
Re: small count problem
Bob,
I cant use
SELECT COUNT(Distinct Points) FROM MyTable
Syntax error (missing operator) in query expression 'COUNT(DISTINCT
Points)'.
/Lasse
"Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
news:ugh3MNK1DHA.2396@TK2MSFTNGP09.phx.gbl...> Aaron Bertrand [MVP] wrote:>> >> >> Anyways, if you WERE using SQL Server, you would be in luck, because
> >> T-SQL's COUNT function allows the use of the DISTINCT keyword, as in:
> >> SELECT COUNT(DISTINCT Points) ...
> > You could also use the GROUP BY and HAVING clause.
> I'm not sure how that would work in this case ... can you go into more
> detail?
>
> Bob Barrows
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>
Lasse Edsvik Guest
-
Bob Barrows #13
Re: small count problem
I did say that you could not use this in Access (JetSQL). You either have to
use my subquery solution:
Create a query using this SQL:
SELECT DISTINCT Points FROM Players
Save it as qDistinctPoints
Then create a new query with this SQL:
SELECT COUNT(*)+1 FROM qDistinctPoints WHERE Points>8
OR
SELECT COUNT(*)+1 FROM (
SELECT DISTINCT Points FROM Players WHERE Points>8) q
OR Chris's self outer join solution.
Bob Barrows
Lasse Edsvik wrote:--> Bob,
>
> I cant use
>
> SELECT COUNT(Distinct Points) FROM MyTable
>
> Syntax error (missing operator) in query expression 'COUNT(DISTINCT
> Points)'.
>
>
> /Lasse
>
>
> "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
> news:ugh3MNK1DHA.2396@TK2MSFTNGP09.phx.gbl...>> Aaron Bertrand [MVP] wrote:>>>>>> Anyways, if you WERE using SQL Server, you would be in luck,
>>>> because T-SQL's COUNT function allows the use of the DISTINCT
>>>> keyword, as in: SELECT COUNT(DISTINCT Points) ...
>>>
>>> You could also use the GROUP BY and HAVING clause.
>> I'm not sure how that would work in this case ... can you go into
>> more detail?
>>
>> Bob Barrows
>>
>> --
>> Microsoft MVP -- ASP/ASP.NET
>> Please reply to the newsgroup. The email account listed in my From
>> header is my spam trap, so I don't check it very often. You will get
>> a quicker response by posting to the newsgroup.
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows Guest



Reply With Quote

