[thelist] SQL 'Buckets' - Was: way OT -- keyboard woes

Joshua Olson joshua at alphashop.com
Wed Oct 17 07:43:32 CDT 2001


Rudy,

: ah, rankings...... [sigh]
:
: no, there is no simple way
:
: it would be easiest to use an auto_increment field and just display that

So long as you avoid DB that cannot do subselect, why not?  There IS a way
that doesn't use grouping or anything and it's not tooooo complex, though
not very efficient.  But, with correct indexing, it should not be too bad.

Try something like this?

SELECT
  a,
  b,
  c,
  (SELECT Count(*)
    FROM [table] t2
    WHERE [where_condition]
    AND [rank_condition]) AS rank
FROM [table] t1
WHERE [where_condition]
ORDER BY [order_condition]

The [rank_condition] is going to be related to the [order_condition].  For
example, if your [order_condition] is "date_created ASC" then the
[rank_condition] would be "t2.date_created < t1.date_created"

Make sense?

-joshua





More information about the thelist mailing list