我正在尝试创建一个表格,我可以在其中获取平均值,然后按名称对这些平均值进行分组。这是我编写的当前SQL,它似乎不起作用。我得到的错误是
SQL错误:ORA-00907:缺少右括号
以下是SQL。有人可以帮忙吗?谢谢
CREATE TABLE new_table_name AS
(Select distinct table_name1.column_name1, AVG(table_name2.column_name2)
FROM table_name1, table_name2
WHERE table_name1.table_id1 = table_name2.table_id2
group by table_name1.column_name1
order BY table_name1.column_name1);
答案 0 :(得分:2)
试试这个:
create table new_table_name as
select t1.column_name1,
AVG(t2.column_name2) column_name2
from table_name1 t1
join table_name2 t2 on t1.table_id1 = t2.table_id2
group by t1.column_name1;
所做的更改:
AVG(t2.column_name2)
DISTINCT
不需要group by