group by 后面能否加子查询?

[复制链接]
查看11 | 回复5 | 2013-10-10 21:39:18 | 显示全部楼层 |阅读模式
如下:
select case when (字段1 in (select 字段2 from 表)) then 1 else 2 end, .....from 表1
group by
case when (字段1 in (select 字段2 from 表)) then 1 else 2 end
回复

使用道具 举报

千问 | 2013-10-10 21:39:18 | 显示全部楼层
It's not!
回复

使用道具 举报

千问 | 2013-10-10 21:39:18 | 显示全部楼层
select g1 from (
select case when (字段1 in (select 字段2 from 表)) then 1 else 2 end, .....) g1 from 表1
)
group by g1

回复

使用道具 举报

千问 | 2013-10-10 21:39:18 | 显示全部楼层
不能.
回复

使用道具 举报

千问 | 2013-10-10 21:39:18 | 显示全部楼层
可以。
如下例所示:
QL> create table t1 as select rownum id,'T1' col1 from dual connect by rownum create table t2 as select rownum id from dual connect by rownum select case when id in (select id from t2) then 1 else 2 end v1,count(*) from t1
2 group bycase when id in (select id from t2) then 1 else 2 end;

V1 COUNT(*)
---------- ----------
1
5
2
95
SQL>
回复

使用道具 举报

千问 | 2013-10-10 21:39:18 | 显示全部楼层
试了一下,是可以的,谢谢!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行