如标题。我要查询最近插入的一行数据,并且状态值等于1,语句应该怎么写呢?比如表名是Student,状态的字段是status

解决方案 »

  1.   

    楼主说的问题不明确~ 您所说的表应该是有个时间的,给个例子,猜是你要的东东。
    if object_id('student') is not null drop table student
    go
    create table  student (idno  char(10) PRIMARY KEY  ,name varchar(20) ,sex  varchar(4), createtime  datetime,status tinyint )
    insert student
    select '001','张三','男','20130401','1'  union all
    select '002','李三','女','20130409','1'  union all
    select '003','王三','男','20130501','1'  union all
    select '004','张五','女','20130301','1'  union all
    select '005','陈六','男','20130512','0'  ---select *  from  student
     select *  from student
     where  createtime  in (select MAX(createtime)  from student where status=1)水平有限,查询语句可能不是最简单的。
      

  2.   

    select * from student where type='最近插入' and stat=1