oracle 查询语句报错"值过多",求大神解救
select gs as 公司,
(
select count(*),gs from 考勤记录表 t
where to_char(t.创建时间,'YYYY-MM')=to_char(sysdate,'YYYY-MM') group by gs
) as 当月累计,(
select count(*),gs from 考勤记录表 t
where to_char(t.创建时间,'YYYY')=to_char(sysdate,'YYYY') group by gs
) as 当年累计
from 考勤记录表
ps:两个子查询都是能查到数据的,第一,二个子查询的结果都只有一条记录,语句是不是写错了?
------解决方案--------------------当月累计和年累计的记录数不会相同,并且没有连接,修改如下
SELECT A.GS,B.Y_COUNT,A.M_COUNT FROM
(SELECT COUNT(*) M_COUNT, GS
FROM 考勤记录表 T
WHERE TO_CHAR(T.创建时间, 'YYYY-MM') = TO_CHAR(SYSDATE, 'YYYY-MM')
GROUP BY GS) A,
(SELECT COUNT(*) Y_COUNT, GS
FROM 考勤记录表 T
WHERE TO_CHAR(T.创建时间, 'YYYY') = TO_CHAR(SYSDATE, 'YYYY')
GROUP BY GS)B
WHERE A.GS=B.GS