sql - "ORA-00998: must name this expression with a column alias" i am having this error can anyone tell me what's the problem and its solution
问题描述
this is my sample code;-
CREATE TABLE orders
(
ord_no int,
purch_amt float,
ord_date varchar(50),
customer_id int,
salesman_id int,
PRIMARY KEY(ord_no)
);
INSERT INTO orders (ord_no, purch_amt, ord_date, customer_id, salesman_id)
VALUES (70001, 150.5, '2012-10-05', 3005, 5002);
CREATE VIEW totalforday
AS SELECT ord_date , COUNT(DISTINCT customer_id),
AVG(purch_amt), SUM(purch_amt)
FROM orders
GROUP BY ord_date;
解决方案
想象一下为您的新视图编写查询。
SELECT ord_date,
COUNT(DISTINCT customer_id),
AVG(purch_amt),
SUM(purch_amt)
FROM totalforday;
您的列名 - 您是在要求一个名为 SUM(purch_amt) 的列,还是要对一个名为 purch_amt 的列进行求和?
您需要为视图提供有效的列名,无论是隐式还是显式。添加别名可以让数据库隐含地找出为您的列命名的内容。
像这样。
CREATE or replace VIEW totalforday
AS SELECT ord_date , COUNT(DISTINCT customer_id) how_many_customers,
AVG(purch_amt) avg_amt, SUM(purch_amt) total_amt
FROM orders
GROUP BY ord_date;
推荐阅读
- html - 子元素:在 Internet Explorer 上悬停不工作 (HTML/CSS)
- javascript - 在 UpdatePanel 内的 Javascript 中使用 ASP.NET 变量
- amazon-web-services - 对于 AWS Cognito 内置登录,“法律文本”出现在哪里?
- ios - 将英语本地化添加到非英语应用程序
- c++ - C++ 中的 LCM 程序
- c# - 在 Xamarin.Forms 中设置开关绑定
- javascript - 如何使用 Three.js 沿弧线打印文本?
- java - Java 类型不匹配无法从 int 转换为 byte?
- angular - 如何使用 Angular-Cli `require` SASS?
- node.js - 使用 mlab 的 ExpressJS 网络应用程序;数据库排序问题