# 请教一个group by语句？

0
[已关闭问题] 关闭于 2012-07-03 14:31

``` A              B           C                   D                           E
----        ---------      ---       ----------------------- ------------------------------------
8293        127.0.0.1       1        2011-07-20 11:22:05.093 829D8513-62CF-DD11-B5DC-001F3ADD178A
8293        127.0.0.1       1        2011-07-20 11:22:16.190 829D8513-62CF-DD11-B5DC-001F3ADD178A
8294        127.0.0.1       0        2011-07-27 16:47:07.897 829D8513-62CF-DD11-B5DC-001F3ADD178A
8294        127.0.0.1       0        2011-07-27 16:47:35.847 829D8513-62CF-DD11-B5DC-001F3ADD178A
8294        127.0.0.1       0        2011-07-27 16:50:56.410 829D8513-62CF-DD11-B5DC-001F3ADD178A
8431        255.255.255.25  1        2011-07-20 13:17:32.397 829D8513-62CF-DD11-B5DC-001F3ADD178A```

```A              B           C                   D                           E
----        ---------      ---       ----------------------- ------------------------------------
8293        127.0.0.1       1        2011-07-20 11:22:05.093 829D8513-62CF-DD11-B5DC-001F3ADD178A
8294        127.0.0.1       0        2011-07-27 16:50:56.410 829D8513-62CF-DD11-B5DC-001F3ADD178A
8431        255.255.255.25  1        2011-07-20 13:17:32.397 829D8513-62CF-DD11-B5DC-001F3ADD178A```

0

select min(A),min(B),......from 表 group by A。

0

`select A, B, C min(D), E from 表 group by A, B, C, E`

@菜鸟程序猿:

`select A, max(B) as B, max(C) as C, max(D) as D, E from 表 group by A, E`

@笨笨蜗牛: 这样不行啊，B是IP，C是bit型用max会出错的

`Operand data type bit is invalid for max operator.`

@菜鸟程序猿: 把B转换一次（使用CAST或者用case-when）再求max。至于IP地址。。。好像是可以求最大最小的吧？如果不行，也只能进行IP转换了（把一个IP转换为整数）。

0

group by A+E

Greatest | 园豆：678 (小虾三级) | 2012-06-25 14:25

group by a, e

group by a+e

0

select * from 表名 group by A

0

Select * From (

Select RW=ROW_NUMBER() OVER(Partition By A,E Order By D asc),* From Table1

) a Where RW=1

Shannon | 园豆：611 (小虾三级) | 2012-07-02 16:53

您需要登录以后才能回答，未注册用户请先注册