SELECT * FORM article where ID=600 OR CLASS<20
现在想写成ID=600 的取top 100
CLASS<20 的取top 2
如何改写?

解决方案 »

  1.   

    写错了,应当是ID=600 的取top 10
      

  2.   

    用if ... else ...
    这个没办法case when。别想了
      

  3.   


    select top 500 * from tb where id = 600
    union --all 不去重复
    select top 2 * from tb where class < 20
      

  4.   

    select top(100) from tb where id=600
    union
    select top(2) from tb where class<20
      

  5.   


    union后面加了all就把重复行也显示出来
      

  6.   


    select top(10) from tb where id=600
    union --自动去重
    select top(2) from tb where class<20
      

  7.   


    --SELECT * FORM article where ID=600 OR CLASS<20
    --现在想写成ID=600 的取top 100
    --CLASS<20 的取top 2
    SELECT top 100 * FROM article
    WHERE ID=600
    UNION
    SELECT top 2 * FROM article
    WHERE CLASS<20