select * from [CustomerRegister] WHERE EnterprisRegisterID<'500'这个查询语句可以输出CustomerRegister 小于 500 所有的行,请教下 如果需要让它每个值只为1行 也就是499行(比如 EnterprisRegisterID列的值为(0-2000)而其每个列值有几千行 我只需一个值只输出一行) ,这个怎么样可以实现,谢谢!

解决方案 »

  1.   

    select * from [CustomerRegister] a
    WHERE EnterprisRegisterID<'500' 
    and not exists(select 1 from [CustomerRegister] where EnterprisRegisterID=a.EnterprisRegisterID and id>a.id)
      

  2.   


    select * from [CustomerRegister] a
    WHERE EnterprisRegisterID<'500'  and not exists(select 1 from [CustomerRegister] where EnterprisRegisterID=a.EnterprisRegisterID and ID>a.ID)
      

  3.   

    有了结构和数据就能写SQL语句了
    不过楼主的图挂了
    哪位版主给他编辑一下