| Author |
Topic |
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-04-29 : 06:06:15
|
| User WorkID Moneypaul 1 1000jess 1 2000jeremy 1 1500paul 2 2000jess 2 1000jeremy 2 1500Queue is depends on money. If you pay much you are close the 1st for the queue if you may less you are at the end if queue.I want a result like this for the paul. ( you have to query it by using user only). I tried temp tables but couldnt do it.WorkID Queue 1 32 1It is easy but my i can think it now :( :DMS BLESS US |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2006-04-29 : 06:45:27
|
You can do it with a correlated subquery:select [User] = 'paul', WorkID = 1, [Money] = 1000 into #myTableunion all select 'jess',1,2000union all select 'jeremy',1,1500union all select 'paul',2,2000union all select 'jess',2,1000union all select 'jeremy',2,1500select t1.* ,(select count(*)from #myTable t2 where t1.WorkID = t2.WorkID and t1.Money <= t2.Money) as Queuefrom #myTable t1where [User] = 'Paul'drop table #myTable |
 |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-04-29 : 08:57:11
|
| No, i think i couldnt explain it.That thing is about ads. So if you pay much money than other companies your ad will be at 1 st queue.in my table there are columns like as i wrote above.so, in results it will contain the queue number of your ad depending on your money that paid.MS BLESS US |
 |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-04-29 : 09:01:17
|
| i think it is imposibble. because there will be same USer on the table and you have to query it accoding to user.you have to make a loop but for many records that will kill the server.i will passs it and will solve on other way.MS BLESS US |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2006-04-29 : 09:16:59
|
| Did you even try the query I posted?If this is what you want for user Paul:WorkID Queue1 32 1then that query does exactly what you want.I think you give up much too easily.rockmoose |
 |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-04-29 : 09:32:39
|
| yeah i tried union select but what about for 1000 recordsso i will ? :select [User] = 'paul', WorkID = 1, [Money] = 1000 into #myTableunion all select User,WorkID,Money from tablename ?MS BLESS US |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2006-04-29 : 13:49:30
|
I just posted an example with a temporary table (#myTable).You want to try this statement on your table:select t1.* ,(select count(*) from tablename t2 where t1.WorkID = t2.WorkID and t1.Money <= t2.Money) as Queuefrom tablename t1where [User] = 'Paul' rockmoose |
 |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-04-30 : 08:32:13
|
| ok thx i solved it.i have another question.in that i tried group by but dudunt worked.table JobsuserID-----Word-----Money 1---------name----1000 1---------name1---800 1---------name3---1200 2---------name----1500 2---------name1---600 2----------name3---1800result will be orderd by the highes value of money and will be grouped by word. It will choose the word with the highest amount of money that paid by the userword-----UserID-----Money name----2-----------1500 name1--1-----------800 name3---2----------1800i tried select Word,UserID,Max(money) from jobs group by Word,UserIDbut it doenst give me the result. ii have an alternate way but it will cause server to work harderMS BLESS US |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2006-04-30 : 08:40:36
|
| try:select Jobs.Word, Jobs.UserID, Jobs.Moneyfrom Jobs inner join (select Word,max(Money) as Money from Jobs) highestMoneyPerWordon Jobs.Word = highestMoneyPerWord.Word and Jobs.Money = highestMoneyPerWord.Moneyrockmoose |
 |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-04-30 : 09:01:16
|
| yeah rightbut select Word,max(Money) as Money from Jobs) after that it needs group by i think :D ok i made it thx againMS BLESS US |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2006-04-30 : 09:08:28
|
You are right, I forgot the group by. rockmoose |
 |
|
|
|