ORACLE 查询中.如下代码,目标是以A分组,查询B的数量 大于 C和A的差.不适用循环语句.只单纯查询语句求实现
CREATETABLETEST(ANUMBER,BNUMBER,CNUMBER)/INSERTINTOTESTVALUES(1,1,2);INSERTINTOTESTVA...
CREATE TABLE TEST(
A NUMBER,
B NUMBER,
C NUMBER
)
/
INSERT INTO TEST VALUES(1,1,2);
INSERT INTO TEST VALUES(1,1,2);
INSERT INTO TEST VALUES(1,1,2);
INSERT INTO TEST VALUES(2,2,5);
INSERT INTO TEST VALUES(2,2,5);
SELECT A FROM (
上面代码没复制完.
CREATE TABLE TEST(
A NUMBER,
B NUMBER
)
/
INSERT INTO TEST VALUES(1,1,2);
INSERT INTO TEST VALUES(1,1,2);
INSERT INTO TEST VALUES(1,1,2);
INSERT INTO TEST VALUES(2,2,5);
INSERT INTO TEST VALUES(2,2,5);
SELECT A FROM (
SELECT * FROM TEST WHERE B IN(2,3)) GROUP BY A HAVING COUNT(B) > (SELECT (C - A) FROM TEST) 这是我自己写的.语句是有问题的,返回多个值,大概是这个意思. 展开
A NUMBER,
B NUMBER,
C NUMBER
)
/
INSERT INTO TEST VALUES(1,1,2);
INSERT INTO TEST VALUES(1,1,2);
INSERT INTO TEST VALUES(1,1,2);
INSERT INTO TEST VALUES(2,2,5);
INSERT INTO TEST VALUES(2,2,5);
SELECT A FROM (
上面代码没复制完.
CREATE TABLE TEST(
A NUMBER,
B NUMBER
)
/
INSERT INTO TEST VALUES(1,1,2);
INSERT INTO TEST VALUES(1,1,2);
INSERT INTO TEST VALUES(1,1,2);
INSERT INTO TEST VALUES(2,2,5);
INSERT INTO TEST VALUES(2,2,5);
SELECT A FROM (
SELECT * FROM TEST WHERE B IN(2,3)) GROUP BY A HAVING COUNT(B) > (SELECT (C - A) FROM TEST) 这是我自己写的.语句是有问题的,返回多个值,大概是这个意思. 展开
3个回答
展开全部
oracle数据库的分组查询语句,主要是根据一个字段,使用关键字group by来分组,如下代码:
select to_char(date_column, 'yyyy-Q'),count(*)
from xxx
where date_column between '01-Jan-2007' and '31-Dec-2009'
group by to_char(date_column, 'yyyy-Q')//分组查询
select to_char(date_column, 'yyyy-Q'),count(*)
from xxx
where date_column between '01-Jan-2007' and '31-Dec-2009'
group by to_char(date_column, 'yyyy-Q')//分组查询
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select a from test
group by a
having count(B)>count(C)-count(A)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询