Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Aamit1
Starting Member
1 Post |
Posted - 2008-12-11 : 05:09:37
|
| Table-> cat_usersid cat_id user_id81 7 12160 7 22193 7 26213 7 29223 7 30Table-> categoriesid parent_id cat7 NULL Stive11 0 Akshay15 NULL Shooting24 NULL Fighting52 NULL PuzzleTable-> Usersid valid name date_added1 1 Holly NULL3 1 Tom 2007-11-017 1 Stive 2007-11-0210 1 Elite 2007-11-0211 1 Akshay 2007-11-02Table-> ratingsid user_id rating date_added1 7 4 2008-07-182 7 3 2008-07-183 3 4 2008-07-184 5 3 2008-07-185 10 2 2008-07-186 6 4 2008-07-187 1922 5 2008-07-1815 1322 3 2008-08-0216 2055 3 2008-08-0781 74 4 2008-08-25160 169 5 2008-08-25$sql1 = "select users.*, round(avg(rating)) as rating, date_format(date_added,'%Y-%m-%d') as `date`from usersleft join ratings on (ratings.user_id = users.id)inner join cat_users on cat_users.user_id = users.idwherevalid = 1and users.id in (select user_idfrom cat_userswhere cat_id = $cat_id)and users.date_added <= now()group by users.idorder by date_added desc, rating desc, name";$max = GetSQL("select count(*) from ($sql1) counter");I am not giving all database it's very largeso got output like ....id user_id rating date_created123 1 4 2008-12-09211 1 3 2008-12-0833 1 4 2008-11-3045 1 3 2008-10-3157 1 2 2008-10-31666 1 4 2008-08-25723 1 5 2008-08-2515 1 3 2008-08-2516 1 3 2008-08-2581 1 4 2008-08-25160 1 5 2008-08-25after that i want to display...after 1 weeklike...id user_id rating date_created160 1 5 2008-08-25 .....change123 1 4 2008-12-09 last data take 1st position211 1 3 2008-12-0833 1 4 2008-11-3045 1 3 2008-10-3157 1 2 2008-10-31666 1 4 2008-08-25723 1 5 2008-08-2515 1 3 2008-08-2516 1 3 2008-08-2581 1 4 2008-08-25again after 1 week ...id user_id rating date_created81 1 4 2008-08-25 .....change160 1 5 2008-08-25 last data take 1st position123 1 4 2008-12-09211 1 3 2008-12-0833 1 4 2008-11-3045 1 3 2008-10-3157 1 2 2008-10-31666 1 4 2008-08-25723 1 5 2008-08-2515 1 3 2008-08-2516 1 3 2008-08-25How to do that??can i add column like position_id so that change position of data??Reason behind change position is old user viewed there profile by another users. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-11 : 09:50:27
|
| Are you using MS sql server? if not, try posting this in some other forums specific to your db type like www.dbforums.com. This is MS Sql Server forum. |
 |
|
|
|
|
|