在Oracle数据库中,指定一组所有数据
SELECT sum(price)
FROM tabA
GROUP BY ()
我理解这里可以省略GROUP BY
子句,但如果我们明确包含,那么完整形式是GROUP BY ()
吗?这取自GROUPING SETS的文档。
我记得曾经读过一次,GROUP BY NULL
具有相同的含义。这是对的吗?否则GROUP BY NULL
意味着什么?
答案 0 :(得分:2)
聚合by()与聚合无值或常量值是一回事。 例如:
create table test_group(cod varchar2(16), descr varchar2(16), num number);
insert into test_group values ('a', 'letter A', 10);
insert into test_group values ('b', 'letter b', 20);
insert into test_group values ('b', 'letter B', 35);
insert into test_group values ('c', 'letter c', 70);
insert into test_group values ('c', 'letter c', 99);
无价值汇总
SQL> select sum(num)
2 from test_group;
SUM(NUM)
----------
234
按null
SQL> select sum(num)
2 from test_group
3 group by null;
SUM(NUM)
----------
234
按()
汇总:
SQL> select sum(num)
2 from test_group
3 group by ();
SUM(NUM)
----------
234
按常数值汇总:
SQL> select sum(num)
2 from test_group
3 group by 'constant';
SUM(NUM)
----------
234
您必须明确写下您的聚合条件:
SQL> select *
2 from test_group
3 group by *;
group by *
*
ERROR at line 3:
ORA-00936: missing expression