【问题标题】:I have to create a view with following attributes我必须创建一个具有以下属性的视图
【发布时间】:2021-07-24 08:40:13
【问题描述】:

创建一个名为 customer_mobile_details 的视图,该视图具有以下属性。显示客户id、客户姓名、手机号码、销售id、净额、型号名称和手机制造商名称,他们已购买。根据客户ID、客户名称、销售ID升序排列记录。enter image description here

我的代码如下。

create view customer_mobile_details 
as( select Customer_Info.Customer_ID, Customer_Info.Customer_Name, 
Distributor.Mobilenumber,
Sales_Info.Salesid, Sales_Info.Net_Amount,
Mobile_Master.Model_Name, Mobile_Master.Manufacturer
from Customer_Info
inner join Sales_Info
on Customer_Info.Customer_ID = Sales_Info.Customer_ID
inner join Mobile_Master
on Sales_Info.Price = Mobile_Master.Price
inner join Distributor
on Mobile_Master.Distributor_ID = Distributor.Distributor_ID)
order by Customer_Info.Customer_ID, Customer_Info.Customer_Name, Sales_Info.Salesid asc;

但我遇到了一些错误。它说 测试失败 测试用例2:检查属性名称、约束、排序等。

有人可以帮我找出我犯错的地方吗?

【问题讨论】:

  • “失败的测试用例 2”不是 Oracle 错误消息。这段代码是否正在被某种教学工具检查?
  • 是的。有2个测试用例。测试用例 1 已成功执行。但是我在测试用例 2 中遇到了这个错误。
  • 这个加入是否正确'INNER JOIN Mobile_Master ON Sales_Info.Price = Mobile_Master.Price'?这个连接不应该使用 IME_NO 吗?
  • 先生,我已经使用 IME_NO 执行了代码。但仍然得到同样的错误。我在哪里做错了?
  • 视图中的order by(如果允许)是多余的,通常会被忽略。事实上,由于括号,语法看起来不太好。

标签: sql oracle inner-join


【解决方案1】:
You can try this one. Works for me.
This is pretty self explanatory.
create view customer_mobile_details as 
(select customer_id,
customer_info.customer_name,
customer_info.mobile,
sales_info.salesid,
sales_info.net_amount,
mobile_master.model_name,
mobile_master.manufacturer
from customer_info
join sales_info using(customer_id)
join mobile_master using(ime_no))

order by customer_id,
customer_info.customer_name,
sales_info.salesid;

【讨论】:

  • 很高兴指出问题中查询的问题。
【解决方案2】:

问题实际上在于问题,因为要获取的手机号码是“Customer_info”表中名为“Mobile”的属性,而不是“Distributor”表中的“mobilenumber”属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 2020-04-13
    • 2019-05-17
    • 2015-05-28
    相关资源
    最近更新 更多