最新的Sql笔试题及答案,部门表,⽤户表,客户信息表,订
单表
部门表(SM_DEPT)
字段名称数据类型是否主键注释
DEPT_ID NUMBER Y部门ID
PARENT_DEPARTMENT_ID NUMBER N上级部门DEPARTMENT_NAME VARCHAR2(50)N部门名称
⽤户部门中间表(SM_USER_DEPT)
字段名称数据类型是否主键注释
ID NUMBER Y主键
DEPT_ID NUMBER N部门ID
USER_ID NUMBER N⽤户ID
⽤户表(SM_USER)
字段名称数据类型是否主键注释
USER_ID NUMBER Y⽤户ID
USER_NAME VARCHAR2(50)N⽤户名称
LOGON_NAME VARCHAR2(50)N登录名
IS_SALES VARCHAR2(1)N是否为业务员
客户信息表(CTM_CUSTOMERS)
字段名称数据类型是否主键注释
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备注
订单头表(PIM_HEADERS)
字段名称数据类型是否主键注释
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汇率
订单⾏表(PIM_LINES)
字段名称数据类型是否主键注释
PI_ID NUMBER N订单ID
PI_LINES_ID VARCHAR2(50)Y订单⾏ID
PRODUCT_CODE NUMBER N产品编码
QUANTITY NUMBER N产品数量
PRICE NUMBER N产品单价
问题
malformed1.编写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
python菜鸟代码大全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
mysql面试题笔试,t5.DEPARTMENT_NAME
from SM_CUSTOMERS t1
left join PIM_HEADERS t2
采煤机scalar什么意思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
6.编写SQL语句,查询出所有的客户的PI订单的下单⾦额,显⽰客户名称,订单币种,订单总数量及订单总额
select
t2.CUSTOMER_NAME
,t1.CURRENCY_CODE
,t3.TOTAL
,t4.TOTAL_MONEY
from PIM_HEADERS t1
left join CTM_CUSTOMERS t2
on t1.CUSTOMER_ID = t2.CUSTOMER_ID
left join (
select PI_ID,sum(QUANTITY) TOTAL,sum(QUANTITY*PRICE) TOTAL_MONEY
from PIM_LINES
motif分析group by PI_ID
) t3
on t1.PI_ID = t3.PI_ID;
7.编写函数,函数需传⼊部门ID,返回结果部门对应所有业务员姓名连接起来,中间⽤逗号隔开
create or replace function getUserByDeptId
( dept_id number) return varchar2
is
res varchar2(200);
cursor mycursor(did number) is
select t2.CUSTOMER_NAME
from (select *
from SM_USER_DEPT
where dept_id = did
) t1
left join SM_USER t2
on t1.USER_ID = t2.USER_ID ;
begin
for c_row in mycursor(dept_id) loop
res := res ||','|| c_row
end loop;
return res;
end;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论