第一个 假如有个表X 当中只有一列Y是姓名 查询不同的姓名个数 
第2个 查询年龄当中第2大年龄的语句,最大的是MAX 第2大的怎么写啊

解决方案 »

  1.   

    1:
    select count(distinct y) from x2:select top 1 age from t 
    where age not in(select max(age) from t)
    order by age desc
      

  2.   

    top 1 是什么意思
    select top 1 age from t 
    where age not in(select max(age) from t) 
    order by age desc 
    查询年龄按降序排列 查询的不是最大的年龄 查到的是第2个数据 是这个意思吗 TOP 1指的就是第2个数据 是这个意思吗?
      

  3.   

    top1,是选择库中的第一条记录
    select top 1 age from t 
    where age not in(select max(age) from t) 
    order by age desc 
    上面语句的意思就是选择年龄不包含第一大年龄的记录,然后排序,然后再从其中选择第一条记录,也就是第二大年龄的记录