Oracle 最新的 Sql 笔试题及答案,Java 面试真题解析火爆全网
===========================================================================
| 字段名称 | 数据类型 | 是否主键 | 注释 |
| :-- | :-- | --- | :-- |
| USER_ID | NUMBER | Y | 用户 ID |
| USER_NAME | VARCHAR2(50) | N | 用户名称 |
| LOGON_NAME |
VARCHAR2(50) | N | 登录名 |
| IS_SALES | VARCHAR2(1) | N | 是否为业务员 |
===================================================================================
| 字段名称 | 数据类型 | 是否主键 | 注释 |
| :-- | :-- | --- | :-- |
| CUSTOMER_ID | NUMBER | Y | 客户 ID |
| CUSTOMER_NAME | VARCHAR2(50) | N | 客户姓名 |
| CITY | VARCHAR2(50) | N | 所属城市 |
| STATE | VARCHAR2(25) | N | 所属州 |
| ZIP_CODE | VARCHAR2(10) | N | 邮政编码 |
| CONTACT_NAME | VARCHAR2(50) | N | 联系人 |
| ADDRESS | VARCHAR2(50) | N | 联系地址 |
| TYPE | VARCHAR2(50) | N | 客户类型 |
| COMMENTS | VARCHAR2(100) | N | 备注 |
================================================================================
| 字段名称 | 数据类型 | 是否主键 | 注释 |
| :-- | :-- | --- | :-- |
| PI_ID | NUMBER | Y | 订单 ID |
| PI_NO | VARCHAR2(50) | N | 订单号 |
| CREATION_DATE | DATE | N | 创建日期 |
| CUSTOMER_ID | NUMBER | N | 关联客户表的客户 ID |
| OPERATOR_ID | NUMBER | N | 关联用户表的用户 ID |
| CURRENCY_CODE | VARCHAR2(50) | N | 订单币种 |
| EXCHAHGE_RATE | NUMBER | N | 汇率 |
==============================================================================
| 字段名称 | 数据类型 | 是否主键 | 注释 |
| :-- | :-- | --- | :-- |
| PI_ID | NUMBER | N | 订单 ID |
| PI_LINES_ID | VARCHAR2(50) | Y | 订单行 ID |
| PRODUCT_CODE | NUMBER | N | 产品编码 |
| QUANTITY | NUMBER | N | 产品数量 |
| PRICE | NUMBER | N | 产品单价 |
================================================================
1.编写 SQL 语句,查询 PIM_HEADERS 表,符合日期在 2011-03-01 和 2011-03-25 之间的 PI 订单,显示订单号,创建日志,订单客户名称,订单业务员名称
select
t1.PI_NO
,t1.CREATION_DATE
,t2.CUSTOM_NAME
,t3.USER_NAME
from (select
from PIM_HEADERS
where CREATION_DATE between
to_date('2011-03-01','yyyy-mm-dd')
and
to_date('2011-03-25','yyyy-mm-dd')
) t1
left join CTM_CUSTOMERS t2
on t1.CUSTOMER_ID = t2.CUSTOMER_ID
left join SM_USER t3
on t1.OPERATOR_ID = t3.USER_ID
2.编写 SQL 语句,查询所有部门名称及其给部门的业务员的个数,部门在 2011-01-01 到 2011-03-01 之间创建的 PI 订单数
select t1._DEPARTMENT_NAME,count(t2.USER_NAME),count(t3.PI_NO)
from SM_DEPT t1
left join SM_USER_DEPT t2
on t1.dept_id = t2.dept_id
left join (select
from PIM_HEADERS
where CREATION_DATE between
to_date('2011-01-01','yyyy-mm-dd')
and
to_date('2011-03-01','yyyy-mm-dd')
) t3
on t2.user_id = t3.OPERATOR_ID
group by t1.DEPT_ID
3.编写 SQL 语句,查询所有客户及其相关 PI 订单号,PI 创建日期,PI 订单相关业务员姓名及其业务所属部门名称
select
t1.*
,t2.PI_NO
,t2.CREATION_DATE
,t3.USER_NAME
,t5.DEPARTMENT_NAME
from SM_CUSTOMERS t1
left join PIM_HEADERS t2
on t1.CUSTOER_ID = t2.CUSTOMER_ID
left join SM_USER t3
on t2.OPERATOR_ID = t3.user_id
left join SM_USER_DEPT t4
on t3.USER_ID = t4.USER_ID
left join SM_DEPT t5
on t4.DEPT_ID = t5.DEPT_ID
4.编写 SQL 语句,更新没有下过 PI 订单的客户名称的备注为“从未发生业务往来”
update CTM_CUSTOMERS t1 set COMMENTS = '从未反生业务往来'
where not exists (
select PI_NO from PIM_HEADERS t2
where t2.CUSTOMER_ID = t1.CUSTOMER_ID
) ;
commit;
5.编写 SQL 语句,查询所有客户名称及其所属城市,并按照城市名称降序,用户名称升序排序
select CUSTOM_NAME,CITY
from CTM_CUSTOMERS
order by city desc,CUSTOMER_NAME asc
评论