ОРИГИНАЛЬНЫЙ ВОПРОС: Этот простой запрос является действительным SQL сгруппированным оператором. Что мне не хватает? Каждое поле группировки входит в группу как?
РЕДАКТИРОВАТЬ: я смог запустить запрос, просто приведя SUM к десятичному числу. Может ли кто-нибудь объяснить ниже?
Нерабочий запрос:
/* ERROR: not a group by expression */
select account, to_char(trans_date, 'mm-yyyy') mnth_yr,
sum(total_duration)/60 as mou
from chuck.cdr_data_summary@chuckdb
where rate_band_type = 'ALC1' and account = '0204927766' and description_text like '%Inbound%'
and trans_date >= '01-jan-2019' and trans_date < '01-jan-2020'
group by account, to_char(trans_date, 'mm-yyyy')
order by account;
Рабочий запрос:
/* no error; only change was the cast(... as decimal..)*/
select account, to_char(trans_date, 'mm-yyyy') mnth_yr,
cast(sum(total_duration)/60 as decimal(18,2)) as mou
from chuck.cdr_data_summary@chuckdb
where rate_band_type = 'ALC1' and account = '0204927766' and description_text like '%Inbound%'
and trans_date >= '01-jan-2019' and trans_date < '01-jan-2020'
group by account, to_char(trans_date, 'mm-yyyy')
order by account;
РЕДАКТИРОВАТЬ: за комментарий, вот мой SQL* PLUS сеанс :
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
SQL> select account, to_char(trans_date, 'mm-yyyy') mnth_yr,
2 (sum(total_duration)/60) as mou
3 from chuck.cdr_data_summary@chuckdb
4 where rate_band_type = 'ALC1' and account = '0204927766' and description_text like '%Inbound%'
5 and trans_date >= '01-jan-2019' and trans_date < '01-jan-2020'
6 group by account, to_char(trans_date, 'mm-yyyy')
7 order by account;
select account, to_char(trans_date, 'mm-yyyy') mnth_yr,
*
ERROR at line 1:
ORA-00979: not a GROUP BY expression
ORA-02063: preceding line from CHUCKDB
SQL>