0
  1. 使用 PL/SQL(不是简单的查询)和剧院数据库:报告电影“STATE OF THE UNION”的平均票价。</li>

我有一个数据库 ticket_price 的 PK 为 Ticket_type 并且电影的 PK 为 movie_ID

这是我的代码

SET SERVEROUTPUT ON
DECLARE
V_MOVIE_TITLE
MOVIE_TITLE.MOVIE%TYPE;
V_AVG_PRICE
PRICE.TICKET_PRICE%TYPE;
BEGIN
SELECT MOVIE_TITLE INTO V_MOVIE_TITLE 
FROM MOVIE,
(SELECT AVG(PRICE) INTO V_AVG_PRICE FROM TICKET_PRICE)
TICKET_PRICE
WHERE MOVIE_TITLE = 'STATE OF THE UNION';
DBMS_OUTPUT.PUT_LINE ('MOVIE NAME       AVERAGE PRICE');
DBMS_OUTPUT.PUT_LINE ('======================================');
DBMS_OUTPUT.PUT_LINE (' ' || V_MOVIE_TITLE.MOVIE_ID || '        ' || V_AVG_PRICE.TICKET_PRICE);
END;
/

错误似乎与子查询 avg(price) 有关如何让它正常运行?

4

1 回答 1

0
SET SERVEROUTPUT ON
DECLARE
V_MOVIE_TITLE
MOVIE_TITLE.MOVIE%TYPE;
V_AVG_PRICE
PRICE.TICKET_PRICE%TYPE;
BEGIN
SELECT MOVIE_TITLE INTO V_MOVIE_TITLE 
FROM MOVIE WHERE MOVIE_TITLE = 'STATE OF THE UNION';

SELECT AVG(PRICE) INTO V_AVG_PRICE FROM TICKET_PRICE TICKET_PRICE;

DBMS_OUTPUT.PUT_LINE ('MOVIE NAME       AVERAGE PRICE');
DBMS_OUTPUT.PUT_LINE ('======================================');
DBMS_OUTPUT.PUT_LINE (' ' || V_MOVIE_TITLE.MOVIE_ID || '        ' || V_AVG_PRICE.TICKET_PRICE);
END;
/
于 2013-09-26T00:25:47.067 回答