您的位置:首页 > 其它

OCP-1Z0-051-V9.02-107题

2013-09-24 15:08 357 查看
107. View the Exhibit and examine the structure and data in the INVOICE table.

Which two SQL statements would execute successfully? (Choose two.)





A. SELECT ***G(inv_date ) 类型不一致,不能对date求平均值

FROM invoice;

B. SELECT MAX(inv_date),MIN(cust_id)

FROM invoice;

C. SELECT MAX(***G(SYSDATE - inv_date)) 缺少group by

FROM invoice;

D. SELECT ***G( inv_date - SYSDATE), ***G(inv_amt)

FROM invoice;

Answer: BD

答案解析:

参考:/article/1628979.html
A,不能对date类型求平均数
B,MAX,MIN可以对数值和date求最大值和最小值
C,组合函数,需要分组,错误
D,***G对数值求平均数,正确。

首先创建测试表:

sh@TEST0924> create table invoice
2 (inv_no number(3) not null,
3 inv_date date,
4 cust_id varchar2(4),
5 inv_amt number(8,2)
6 );

Table created.


插入数据后查询:

sh@TEST0924> select * from invoice;

INV_NO INV_DATE CUST INV_AMT
---------- --------- ---- ----------
1 01-APR-07 A10 1000
2 01-OCT-07 B1R 2000
3 01-FEB-07 3000

开始测试:
A答案:AGV函数需要一个数值类型或者可以隐式转为数值类型的参数



sh@TEST0924> SELECT ***G(inv_date ) FROM invoice;
SELECT ***G(inv_date ) FROM invoice
*
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got DATE

AGV function takes as an argument any numeric data type or any nonnumeric data type that can be implicitly converted to a numeric data type. The function returns the same data type as the numeric data type of the argument.

B答案:

sh@TEST0924> SELECT MAX(inv_date),MIN(cust_id)
2 FROM invoice;

MAX(INV_D MIN(
--------- ----
01-OCT-07 A10


C答案:缺少group 不要函数

sh@TEST0924> SELECT MAX(***G(SYSDATE - inv_date)) FROM invoice;
SELECT MAX(***G(SYSDATE - inv_date)) FROM invoice
*
ERROR at line 1:
ORA-00978: nested group function without GROUP BY


sh@TEST0924> SELECT MAX(***G(SYSDATE - inv_date)) FROM invoice
2 group by cust_id;

MAX(***G(SYSDATE-INV_DATE))
--------------------------
2427.62578


可以单独求平均值和最大值。

sh@TEST0924> SELECT ***G(SYSDATE - inv_date)FROM invoice;

***G(SYSDATE-INV_DATE)
---------------------
2327.29273

sh@TEST0924> SELECT MAX(SYSDATE - inv_date) FROM invoice;

MAX(SYSDATE-INV_DATE)
---------------------
2427.62655


D答案:


sh@TEST0924> SELECT ***G( inv_date - SYSDATE), ***G(inv_amt) FROM invoice;

***G(INV_DATE-SYSDATE) ***G(INV_AMT)
--------------------- -----------
-2327.2942 2000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: