on 2011 Dec 06 3:00 PM
I'd like a query that returns the first two sales for EACH salesperson ordered by date from a main sales table. Each person may have made many sales but I just want the first n when ordered by date.
E.g.
salesperson_id, salesperson_name, sale_id, saledate 1,Tim,1,2011-01-01 1,Tim,2,2011-01-02 3,Fred,1,2011-05-01 3,Fred,2,2011-05-01 4,Julie,1,2011-05-10 4,Julie,2,2011-05-10
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
IMHO, given Breck's sample, that would mean that a single sales person has more than 2 sales on the same date - how are you going to treat that?
If this doesn't occur in your data, then I wouldn't expect problems with RANK() - as it should be used with a partition on each sales person...
BTW, ROWNUMBER() should resolve "ties".
That's what the WHERE clause is for, in your case WHERE ranked.entry_rank <= 2.
User | Count |
---|---|
67 | |
8 | |
8 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.