码迷,mamicode.com
首页 > 其他好文 > 详细

MAX GROUP BY

时间:2016-05-22 20:15:59      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

IF OBJECT_ID(‘TABMAXID‘) IS NOT NULL
DROP TABLE TABMXID
GO
CREATE TABLE TABMXID(
  ID INT IDENTITY(1,1) PRIMARY KEY,
  NAME VARCHAR(50) NOT NULL,
  NUM INT NOT NULL
)
GO
INSERT INTO TABMXID(NAME,NUM)VALUES(1,2)
INSERT INTO TABMXID(NAME,NUM)VALUES(1,3)
INSERT INTO TABMXID(NAME,NUM)VALUES(2,1)
INSERT INTO TABMXID(NAME,NUM)VALUES(2,2)
INSERT INTO TABMXID(NAME,NUM)VALUES(3,3)
INSERT INTO TABMXID(NAME,NUM)VALUES(3,4)
GO
SELECT * FROM dbo.TABMXID
GO
SELECT NAME,MAX(NUM) AS NUM FROM dbo.TABMXID GROUP BY NAME

  

MAX GROUP BY

标签:

原文地址:http://www.cnblogs.com/linhongquan/p/5517537.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!