2006-10-8
表数据:tab1
id    name  num
A     a         9
A     b       11
B     f         7
B     g         8
所要结果:
A   b    11
B    g    8
SQL 语句
select * from tab1
where (num in
              (select max(num) from tabl group by id)
           )
解释说明,之所以要用子查询,目的是要取全部的tab1中的所有列
如果不用子查询,当tab1中含有text或image列的时候是不可以写在group by子句中的


根据生日获得当前年龄
declare @birthday datetime
set @birthday = '1979/8/30'
select datediff(yy,@birthday,getdate())

取insert语句产生的id
seelct   @@identity   或select   scope_identity()

相关文章:

  • 2021-10-25
  • 2021-06-05
猜你喜欢
  • 2021-05-18
  • 2021-09-06
  • 2022-03-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
相关资源
相似解决方案