A. sql面試題
1、首先,將三個表建立一個視圖,可以直接在企業管理器裡面建,也可以將下面的代碼直接復制到查詢分析器裡面執行:
SELECT dbo.students.studentname, dbo.class.classname, dbo.score.course,
dbo.score.score
FROM dbo.class INNER JOIN
dbo.students ON dbo.class.classid = dbo.students.classid INNER JOIN
dbo.score ON dbo.students.studentid = dbo.score.studentid
2、然後,求 各科 班分數 最高的同學的名字,班級名稱,課程名稱,分數 ,代碼如下:
select classname as 班級,course as 學科,max(score) as 最高分,(select top 1 studentname from scoreview where classname=x.classname and course=x.course order by score desc) as 最好成績的學生 from scoreview x group by classname,course
------------
已經經過測試,你自己可以試試
B. sql語句 面試題
A.創建表格CODE省略
註明:學生表PK stu_id 課程表pk cos_id 分數表PK enrollment_id FK stu_id,cos_id
B.插入數據code省略
C.Query
select s.stu_id,stu_name,count(cos_id) from student s,enrollments e where s.stu_id = e.stu_id and e.grade>60 group by s.stu_id,stu_name;
select e.stu_id,s.stu_name,c.cos_name from student s,enrollments e,course c
where s.stu_id = e.stu_id
and e.cos_id = c.cos_id
and c.cos_name = 'CHINESE'
and s.stu_name like 'W%';
select stu_id,stu_name from (select e.stu_id,stu_name,cos_name from enrollments e,student s,course c
where s.stu_id = e.stu_id
and e.cos_id = c.cos_id
and c.cos_name IN ('CHINESE','MUSIC'))
group by stu_id,stu_name
having count(cos_name) = 2
select distinct e.cos_id,c.cos_name,count(e.stu_id) stu_count,count(e.stu_id)-NVL(A.FAIL,0) upscore,(count(e.stu_id)-NVL(A.FAIL,0))/count(e.stu_id) rate from
(select cos_id,count(stu_id) fail from enrollments where grade<60 group by cos_id) a,enrollments e,course c
where e.cos_id = a.cos_id(+)
and e.cos_id = c.cos_id
group by e.cos_id,NVL(a.fail,0),c.cos_name;
update student
set avg_grade =(select avg(grade) X from enrollments group by stu_id
having student.stu_id = enrollments.stu_id);
select stu_id,avg(grade) from
(select stu_id,cos_id,grade,row_number() over(partition by stu_id order by grade ) X from enrollments)
group by stu_id
having count(*)<=2
UNION
select A.stu_id,avg(A.grade)from
(select stu_id,cos_id,grade,row_number() over(partition by stu_id order by grade ) X from enrollments) A,
(select stu_id,count(*) c from
(select stu_id,cos_id,grade,row_number() over(partition by stu_id order by grade ) X from enrollments)
group by stu_id) B
where A.stu_id = B.stu_id
and A.x>1 and x<B.c
group by A.stu_id,b.c
_________________________________________________
環境:oracle 10g/TOAD 以上代碼均通過測試,如有問題,請聯系,謝謝
C. SQL面試題
select name
from
(
select name,sum(score) sc
from 表
group by name
) t1
where t1.sc>200
這樣?
D. SQL語句的幾種優化方法
1、盡可能建立索引,包括條件列,連接列,外鍵列等。
2、盡可能讓where中的列順序與復合索引的列順序一致。
3、盡可能不要select *,而只列出自己需要的欄位列表。
4、盡可能減少子查詢的層數。
5、盡可能在子查詢中進行數據篩選 。
E. 對sql進行優化的原則有哪些
太多了
最主要的幾點:
1 減少返回不必要的數據
2 減少物理和邏輯讀次數
3 減少計算次數
以上兩個方面就優化了 內存 硬碟讀寫 CPU的消耗,
基於以上原則,你可以使查詢跑的更快,數據表設計的更合理。
請採納,如有疑問,及時溝通!
F. 如何進行SQL性能優化
這里分享下mysql優化的幾種方法。
1、首先在打開的軟體中,需要分別為每一個表創建 InnoDB FILE的文件。
G. 工作中常用的幾種sql優化技巧
例如:
1、盡可能建立索引,包括條件列,連接列,外鍵列等。
2、盡可能讓where中的列順序與復合索引的列順序一致。
3、盡可能不要select *,而只列出自己需要的欄位列表。
4、盡可能減少子查詢的層數。
5、盡可能在子查詢中進行數據篩選 。
H. 關於Oracle PL/SQL優化,一面試題,求助
pl/sql是操作資料庫的一種工具軟體; oracle是一種大型資料庫; oracle自帶有sql/plus實際上可以滿足需求,但是用著不是很主觀,plsql提供良好的操作界面,使用起來就很方便,所以,基本上pl/sql已成為oracle必備的工具軟體
I. 一個sql面試題
select t1.name,t2.name from department t1,department t2 where t1.name<t2.name;
********
測試log:
[TEST@ORA1] SQL>select t1.name,t2.name from department t1,department t2 where t1.name<t2.name;
N N
- -
a b
a c
a d
b c
b d
---
以上,希望對你有所幫助。