在sql中分组记录集 [英] Grouping sets of records in sql

查看:26
本文介绍了在sql中分组记录集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

分组在fromtoloc上完成,一组由usrid

The grouping is done on from and toloc and one group is been indicated by usrid

Table :

from   toloc  usrid
a        b      1
c        d      1       --- group 1
e        f      1
-------------------
a        b      2
c        d      2       --- group 2  
e        f      2
----------------------
a        b      3
c        d      3       --- group 3
h        k      3

组集查询后需要的结果集???

after group set query required resulset ???

from   toloc  usrid
a        b      1
c        d      1       --- group 1 & 3 combined to form 1 group
e        f      1
-------------------
a        b      2![alt text][1]
c        d      2       --- group 2  
h        k      2

我怎样才能达到结果集.我必须在 sql 中对类似的记录集进行分组.是否可以使用汇总或新分组集.我想不通.

How can I achieve the resultset. I have to group similar set of records in sql. Is it possible to do with rollup or the new grouping sets. I'm not been able to figure it.

推荐答案

这个问题的答案在这里:https://stackoverflow.com/a/6727662/195446

Answer to this question is here: https://stackoverflow.com/a/6727662/195446

另一种方法是使用 FOR XML PATH 作为记录集的签名.

Another way is to use FOR XML PATH as signature of set of records.

这篇关于在sql中分组记录集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆