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 |
|
laro
Starting Member
3 Posts |
Posted - 2010-05-13 : 04:20:59
|
| Hi,I use MySql,I have a table (products) with the following fields (number (primary key), name)The table order by the number fieldfor example:number | Name-------------1 | aa2 | bb3 |4 |5 | ee6 | ff7 | gg8 |9 |10 |11 |12 | ll13 | mmI need to write a querywhich need to find 3 numberswhich haven't have a nameand theier number are sequentlyfor exmple:in the above examplethe answer will be:8, 9,10I use MYSQL,and I dont know how to right the above queryThanks |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-05-13 : 05:44:36
|
| This site is for MS SQL ServerPost your question at www.mysql.comMadhivananFailing to plan is Planning to fail |
 |
|
|
laro
Starting Member
3 Posts |
Posted - 2010-05-13 : 05:52:05
|
| Ok,So how can I write the query with MS SQL Server ? |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-05-13 : 06:14:08
|
quote: Originally posted by laro Ok,So how can I write the query with MS SQL Server ?
Kind of in hurry.I have written a query that will give the min number & max number matching your criteria.You will just have to find all the numbers between these two numbers.declare @tbl as table(number int,name varchar(40))insert into @tblselect 1,'aa' union allselect 2,'bb' union allselect 8,'' union allselect 9,'' union allselect 10,'' union allselect 11,'ll' union allselect 12,'mm' union allselect 13,'ll' union allselect 14,'' select * from @tblselect MIN(number)AS MINNUMBER,MAX(number)AS MAXNUMBER from( select *,number-ROW_NUMBER()over(partition by name order by name) as rid from @tbl where name='')t group by rid having MAX(number)-MIN(number)=2 PBUH |
 |
|
|
|
|
|
|
|