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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-07-23 : 08:54:38
|
| Virendra writes "Dear Sir, I have a Table A which does not have any primary key. It has a field Price. I want to write a select statement that returns price*2 for every alternate records. For example if i have 10 records, for the 2,4,6,8 and 10th record, the price returned should be price*2. Is it possible in one single SELECT statement?? Hoping to get a quick reply.Thanks and Regards,VSRajput" |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-07-23 : 09:55:05
|
OK, first of all, if you don't have a primary key, you don't have a table. [CELKO]. Said differently, without a unique way to identify a tuple, you are not in 1NF.Second, in relational theory, there is no concept of record order (barring an ORDER BY clause, of course). So the 2,4,6,8 and 10th record is a meaningless concept.Having said that....create table #virendra (price int)insert #virendraselect 1union select 2union select 3union select 4union select 5union select 6union select 7union select 8union select 9union select 10goselect price, price * 2 as [pricetimestwo]from #virendra vwhere ((select count(*) from #virendra where v.price > price) % 2) = 1order by price <O> |
 |
|
|
|
|
|
|
|