select * from tb where id in (3,4,6,7)
实在看不出有什么联系

解决方案 »

  1.   

    LoveCherry(我爱成立) 
    大哥。。也许是我没有说清楚。不是固定要(3,4,6,7)记录。。是要随机取。如果想那么容易我就不问啦
    就是两条故事两天寓言。都是随机的。
      

  2.   

    用批处理啊,一个select 返回故事,一个select返回寓言,用二个表填充DataSet,两个表分绑定你的页面显示的不同地方,这样不是更好?
      

  3.   

    问题是现在就想用一条SQL语句
    自己想过可以用联合。但是总觉得不好。如果类别多了就不好了。
      

  4.   

    select top 2 * from tb  where leibie in  (select distinct leibie from tb )
    随机取有点困难,我想想!
      

  5.   

    用存储过程吧
    declare @count1 int
    declare @count2 int
    select @count1=count(*) from tb where leibie='故事'
    select @count2=count(*) from tb where leibie='寓言'
    declare @a int
    select @a=rand(@count1)
    select * from tb where id=@a
    select @a=rand(@count1)
    select * from tb where id=@a
    select @a=rand(@count2)
    select * from tb where id=@a
    select @a=rand(@count2)
    select * from tb where id=@a
      

  6.   

    说真的我只会这样,
    (SELECT TOP 2 title, leibie
    FROM atc
    WHERE (class_name = '小故事'))
    UNION
    (SELECT TOP 2 title, leibie
    FROM atc
    WHERE (class_name = '小寓言'))
    ORDER BY leibie
    不能随机。如果类别多了就不好弄。就要union很多次
      

  7.   

    生成个随机数i,*1000了取整后得j,select * where id=j
      

  8.   

    select *,newid() as ni 
    into #t 
    from 表 select id,title,leibie
    from #t 
    where (select count(*) from #t where leibie=a.leibie and ni>=a.ni)<=2
    order by leibie
      

  9.   

    改一点
    select *,newid() as ni 
    into #t 
    from 表 select id,title,leibie
    from #t a
    where (select count(*) from #t where leibie=a.leibie and ni>=a.ni)<=2
    order by leibie
      

  10.   

    我对SQL不熟悉。请问
    select *,newid() as ni 
    into #t 
    from 表
    是什么意思特别是 #t