Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. small problem... I hope
      remove the parentheis from the variable names offending code: should be put pfilenummer into member "nummer" put pfilename into member...
    4. 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...
    5. small problem
      Modify > Document > Dimensions -- Patrik steve32880 wrote:
  3. #2

    Default 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

  4. #3

    Default Re: small count problem


    "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
    Shouldn't that only return 1 if you want the number of UNIQUE points greater
    than your value? DO you want unique row counts or unique actual point
    values?
    >
    > SELECT COUNT(*)+1 FROM Players WHERE Points>1
    >
    > should return 4
    I see two unique point values or three unique rows here, not 4.
    >
    > SELECT COUNT(*)+1 FROM Players WHERE Points>11
    >
    > should return 1
    I don't see anything greater than 11 here. What exactly are you after in
    your queries?

    Ray at work


    Ray at Guest

  5. #4

    Default 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

  6. #5

    Default 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

  7. #6

    Default Re: small count problem

    Lasse Edsvik wrote:
    > 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
    I remember from your last post that you were using Access. Is that still the
    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

  8. #7

    Default 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

  9. #8

    Default Re: small count problem

    > 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.

    --
    Aaron Bertrand
    SQL Server MVP
    [url]http://www.aspfaq.com/[/url]


    Aaron Bertrand [MVP] Guest

  10. #9

    Default Re: small count problem

    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.


    Bob Barrows Guest

  11. #10

    Default 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

  12. #11

    Default Re: small count problem

    "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
    >
    >
    Assuming Players.Player is unique, here's an alternative to the
    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

  13. #12

    Default 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

  14. #13

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139