Home News Contact Us Forum About Us Demos Products F.A.Q.
Shopping Cart
You currently have 0 items in your cart.


Recent Events
  • 23/11/2024 Black Friday 2024

    BIG SALE, 30% discount for all our extensions. Use BF24 coupon code. Hurry up the discount is valid till 3 December.

  • 31/12/2023 New Year SALE

    We are glad to announce New Year SALE. 25% discount for all our extensions. Use NY24 coupon code. Hurry up the discount is valid till 7 January.


2Checkout.com, Inc. is an authorized retailer of goods and services provided by ARI Soft. 2CheckOut




Follow us on twitter



Welcome, Guest
Please Login or Register.    Lost Password?

[SOLVED] Rank Results
(1 viewing) (1) Guest
Go to bottomPage: 1
TOPIC: [SOLVED] Rank Results
#30059
[SOLVED] Rank Results 12 Years, 4 Months ago Karma: 2
I'm looking to rank my results obtained through an inner join.

Here is my SQL query:


Code:

SELECT t1.f1, t2.f2, t2.f3, t2.f4, t2.f5
    FROM t1, t2
    WHERE t1.f1=t2.f1 AND t2.f6="{date}"
    ORDER BY f1, f2, f3, f4, f5;



The resulting row set gives me x rows.


I'd like to have a left-most column called Rank, which simply increments. If there is a tie, it'd be nice if the tied entries were all of the same rank, and then the next rank would continue as appropriate. However, I do have 5 fields in my ORDER BY portion, so I doubt that there will be any ties.

I have found this on the net, but it appears that the SQL query textbox does not like multiple statements:

Code:

SET @rank=0;

SELECT @rank:=@rank+1 AS rank, fruit, amount
    FROM sales
    ORDER BY amount DESC;




Any thoughts?
Last Edit: 2012/07/25 12:36 By JugglingReferee.
The administrator has disabled public write access.
 
#30060
Re:Rank Results 12 Years, 4 Months ago Karma: 2
This works!:

Code:

SELECT @curRank := @curRank +1 AS Rank, t1.f1, t2.f2, t2.f3, t2.f4, t2.f5
FROM t1, t2, (
SELECT @curRank :=0
) r
    WHERE t1.f1=t2.f1 AND t2.f6="{date}"
    ORDER BY f1, f2, f3, f4, f5;

The administrator has disabled public write access.
 
Go to topPage: 1