就是有个表。
比如
talbe_1
words
你好
hello
你好1
hello1
你好2
hello2
你好3
hello3
你好4
hello4
我想将table_1中的奇数行和偶数行分别获得并放到两个DataTable里面
求sql 语句,谢谢。

解决方案 »

  1.   

    alter tb add id int identity(1,1)
    go
    select col into  tb1 from tb where id%2=1
    select col into  tb2 from tb where id%2=0
      

  2.   


    with sel as(
    select words,rn=row_number()over(order by getdate()) from tb
    )
    insert into tb1
    select words from sel where rn%2=1
    with sel as(
    select words,rn=row_number()over(order by getdate()) from tb
    )
    insert into tb2
    select words from sel where rn%2=2
      

  3.   

    用row_number()来加一个虚拟id,然后再计算奇偶
      

  4.   

    create table #table_1(words nvarchar(20))
    insert into #table_1
    (words) values('你好'),('hello'),('你好1'),('hello1'),('你好2'),('hello2'),('你好3'),('hello3'),('你好4'),('hello4')create table #test1(words nvarchar(20))
    create table #test2(words nvarchar(20))declare @news varchar(20)
    declare @s varchar(20)
    declare youbiao1 cursor for
    select words from #table_1 where(PATINDEX('%[0-9]%',words)>0 )
    OPEN youbiao1
    FETCH NEXT FROM youbiao1 INTO @s
    WHILE(@@FETCH_STATUS = 0)
    begin
    set @news=@s
    WHILE PATINDEX('%[^0-9]%',@news) > 0
    BEGIN
    set @news=stuff(@news,patindex('%[^0-9]%',@news),1,'')
    END
    if @news%2=1
    insert into #test1(words)values(@S)
    else if @news%2=0
    insert into #test2(words) values(@S)
    FETCH NEXT FROM youbiao1 INTO @s 
      END
    CLOSE youbiao1
    DEALLOCATE youbiao1
    select * from #test1
    select * from #test2比较菜,搞了半天别见笑
      

  5.   

    我这个是access,貌似没有临时表吧。
    我是新手,我不知道怎么把一个sql查询得到的数据成为了一个临时表,然后在从临时表里面查询或是弄成一个别名什么的。
    我不会搞。
    比如
    select * from tb_1
    这样子 我就得到了tb_1里面的数据了。然后我想把这里面的数据当成另外一个别名比如 tb_2
    这样子的做法主要是为了 将tb_2再后面使用。
    select * from tb_2 where 一些条件 
    求指教谢谢。
      

  6.   


    if OBJECT_ID('table1','u') is not null
    drop table table1
    create table table1
    (
    Name nvarchar(20) ,
    ) if OBJECT_ID('table2','u') is not null
    drop table table2
    create table table2
    (
    Name nvarchar(20) ,
    ) go
    with T as 
    (select Name,ROW_NUMBER() over (order by getdate()) RowID from Course)
    insert into Table1 select Name From T where RowID%2=0go
    with T as 
    (select Name,ROW_NUMBER() over (order by getdate()) RowID from Course)
    insert into table2 select Name From T where RowID%2=1goselect *From Course
    select *From table1
    select *From table2--Course
    --1001 数据结构 10001
    --1002 计算机网络 10001
    --1003 C++程序设计 10002
    --1004 计算机算法 10002--table1
    --计算机网络
    --计算机算法--table2
    --数据结构
    --C++程序设计
      

  7.   


    --测试数据
    if OBJECT_ID('Test_20121206') is not null drop table Test_20121206
    go
    create table Test_20121206(value nvarchar(20))
    insert into Test_20121206
    select 'talbe' union 
    select '你好' union 
    select 'talbe1' union 
    select '再见' --查询
    --新增id标示放入一张新增的表中(临时使用)
    select * into table_0 from 
    (select ROW_NUMBER() over(Order by getdate())as id,value from Test_20121206)t
    --奇偶数据分别插入不同表
    select * into table_1 from table_0 where id%2=1--奇数行
    select * into table_2 from table_0 where id%2=0--偶数行
    --删除临时使用的表table_0
    drop table table_0/*查看新增结果
    select * from table_1
    select * from table_2
    id                   value
    -------------------- --------------------
    1                    talbe
    3                    你好(2 行受影响)id                   value
    -------------------- --------------------
    2                    talbe1
    4                    再见(2 行受影响)
    */
      

  8.   

    select name ,time from A ,(select @rownum :=0) tmp_table where (@rownum :=@rownum+1)%2=1; 
    提取奇数行
      

  9.   

    句中 select 内容为我测试数据
      

  10.   


            Dim dt As DataTable = GetKehuanliWord("14,客户案例")
            Dim m_iPageCount = dt.Rows.Count
            If m_iPageCount <= 0 Then
                Exit Function
            End If
            Dim dtJishu As DataTable
            Dim dtOushu As DataTable
            dtJishu = dt.Copy
            dtOushu = dt.Copy
            Dim iIndex As Integer = 0
            For iIndex = m_iPageCount - 1 To 0 Step -1
                If iIndex Mod 2 = 0 Then
                    dtJishu.Rows.RemoveAt(iIndex)
                Else
                    dtOushu.Rows.RemoveAt(iIndex)
                End If
            Next我是这样写的。用了两个table