1.select 學號,姓名 from 學生 where 學號 not in (select 學號 from 選課)
2. select 學號,姓名 from 學生 where 學號 in (select 學號 from 選課 where 成績<60 and 課號=(select 課號 from 課程 where 課名='VB'))
3. select a.學號,b.成績 from 學生 as a,選課 as b where a.學號=b.學號 amd b.課號 in (select 課號 from 課程 where 學分>3 )
2. 資料庫期末考試
如下 (PS:簡單起見全部使用的varchar2 有些按需要可改成int )
[oracle@rhel3 admin]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Proction on Fri Apr 10 13:21:11 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Proction
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create table student(sno varchar2(10) primary key,sname varchar2(20),ssex char(2),sbirthday varchar2(20),sdept varchar2(20));
Table created.
SQL> create table courses(cno varchar2(10) primary key,cname varchar2(20),ccredit varchar2(10));
Table created.
SQL> create table sc(sno varchar2(10),cno varchar2(10),grade varchar2(10));
Table created.
SQL> alter table sc add constraint pk_sc primary key (sno,cno);
Table altered.
1 select sno,sname from student;
2 select sno,sname,sdept from student;
3 select * from student;
4 select sno,sbirthday from student;
5 select sno,sbirthday,lower(sdept) sdept from student;
6 select sno xingm,sbirthday csrqi,sdept xim from student;
7 select distinct(sno) from student where sno in (select sno from sc where cno in (select cno from courses where cpno is not null));
8 select * from student where sdept='jisuanji';
9 .1 select sname,round(months_between(sysdate,to_date(sbirthday,'yyyy-mm-dd')),0)/12 nianji from student where sbirthday<add_months(sysdate,-12*20);
9.2 select sname,round(months_between(sysdate,to_date(sbirthday,'yyyy-mm-dd')),0)/12 nianji from student where months_between(sysdate,to_date(sbirthday,'yyyy-mm-dd'))/12<20;
10 select distinct(sno) from sc where grade<'60';
未完待續......看的真累
11 select sname,sdept,round(months_between(sysdate,to_date(sbirthday,'yyyy-mm-dd')),0)/12 nianlin from student where months_between(sysdate,to_date(sbirthday,'yyyy-mm-dd'))/12 between 20 and 30;
12 select sname,sdept,round(months_between(sysdate,to_date(sbirthday,'yyyy-mm-dd')),0)/12 nianlin from student where months_between(sysdate,to_date(sbirthday,'yyyy-mm-dd'))/12 <20 or months_between(sysdate,to_date(sbirthday,'yyyy-mm-dd'))/12>30;
13 select sname,ssex from student where sdept in ('xinxi','shuxue','jisuanji');
14 select sname,ssex from student where sdept not in ('xinxi','shuxue','jisuanji');
15 select * from student where sno like '95001%';
16 select sname,sno,ssex from student where sname like 'liu%';
17 select sname from student where sname like 'ouyang%' and length(sname)=6;
18 select sname,sno from sutdent where substr(sname,2,1)='yang';
19 select sname from student where sname not like 'liu%';
20 select cno,ccredit from courses where cname like 'C%';
21 select cno,credit from courses where cname like 'H%' and substr(cname,length(cname)-3,1)='T';
歇會....................
22 select sno,cno from sc where cno in (select cno from courses where cpno is not null) and grade is null;
23 select sno,cno from sc where grade is null;
24 select sname from student where sdept='jisuanji' and (months_between(sbirthday,sysdate)/12)<20;
25 select sname,ssex from student where sdept='jisuanji' or sdept='shuxue' or sdept='xinxi';
26 select sno,grade from sc where cno='3' order by grade desc;
27 select * from student order by sdept asc,sbirthday desc;
28 select count(1) from student;
29 select count(sno) from sc where cno in (select cno from courses where cpno is not null);
30 ...........
PS : courses 那個表好像建表的時候多打了個s
3. 資料庫期末考試題 編寫SQL語句 1.創建一張學生表,包含以下信息,學號,姓名,年齡,性別,家庭住址,聯系
create table 學生表
(
學號 char(10) primary key,
姓名 char(10),
年齡 int,
性別 char(2) check (sex IN ('男','女')),
家庭住址 char(40),
聯系 char(20)
)
4. 資料庫題目,這兩天考試用,要全部用SQL語句,哪位高手幫忙做下,謝謝了。
1.CREATE DATABASE TEST;
2.USE KAOSHI;
CREATE TABLE STUDENT
(
XUEHAO NCHAR(10) PRIMARY KEY,
XINGMING NCHAR(8) UNIQUE,
BANJI NCHAR(10)
)
3.USE TEST;
CREATE TABLE COURSE
(
KECHENGHAO NCHAR(4) PRIMARY KEY,
KECHENGMING NCHAR(10) UNIQUE,
XUEFEN INT
)
4.USE KAOSHI;
CREATE TABLE SCORE
(
XUEHAO NCHAR(10) PRIMARY KEY,
KECHENGHAO NCHAR(4) UNIQUE,
CHENGJI INT,
XUEQI NCHAR(10)
)
5.ALTER TABLE KAOSHI.STUDENT
ADD CONSTRAINT fk_stuInfo_stuNo FOREIGN KEY (XUEHAO) REFERENCES KAOSHI.SCORE(XUEHAO);
ALTER TABLE TEST.COURSE
ADD CONSTRAINT fk_stuInfo_COUNO FOREIGN KEY (kechenghao) REFERENCES KAOSHI.SCORE(KECHENGHAO);
update SCORE T SET T.BEIZHU='及格' WHERE T.CHENGJI<60 PS.創建的表中沒有備注這一列。感覺這題有歧義
CREATE VIEW YOUXIUXINXI AS
SELECT T.XUEHAO,T.XINGMING,T1.KEHCENGHAO,T1.KECHENGMING,T3.BEIZHU
FROM STUDENT T,COURSE T1,SCORE T3 WHERE T3.BEIZHU='不及格'
ORDER BY T.XUEHAO
CREATE PROCEDURE GERDRADE(V_XUEHAO NCHAR(10))
AS
BEGIN
SELECT XINGMING ,KECHENGMING,CHENGJI FROM SCORE T LEFT JOIN
COURSE T1 ON T.KECHENGHAO=T1.KECHENGHAO
LEFT JOIN STUDENT T2 ON T.XUEHAO=T2.XUEHAO
WHERE T2.XUEHAO=V_XUEHAO
END
5. 資料庫原理期末題中的一個用SQL語句查詢的題,是圖中的第7小題
select cno from C where tno = 6 //查出業務是6 的主營公司
select count(1) from C where tno = 6 //查出業務是6 的主營公司總數
select count(1),cno from CT where tno !=6 and cno in ( select cno from C where tno = 6) group by cno 根據主營是6的公司 查出非6 的其他營業業務 和數量
select
b from (select count(1) a,cno b from CT where tno !=6 and cno in (
select cno from C where tno = 6)group by cno) where a =( select count(1) from C
where tno = 6) 根據數量對比 查出伴生業務號
其他的就根據業務號查了
思路是 根據C查出公司號,根據公司號在CT表裡篩選 ,業務號是非6的其他業務 這樣查出 2 3 1 業務 因為是半生的 所以數量一定和公司數量一致 根據公司數量對比一下就出來了 。也不確定理解的對不對,我是這樣想的。
C表
公司號 主營業務
A 6
B 3
C 6
CT表
公司號 營業務號
A 6
A 2
A 3
B 3
C 6
C 3
C 1
6. 資料庫SQL語句考試
1.
create table A (
S# varchar(20) primary key,
SN varchar(20),
Sex varchar(2),
Age number(10),
Dept varchar(50));
create table B (
C# varchar(20) primary key,,
CN varchar(20));
create table C (
S# number(10),
C# number(10),
Grade number(10));
2.
insert into table A(S#,Sn,Dept) values('010102','張靜','機電');
3.
update C set grade=59 where grade>=60;
4.
delete * from C where S# in (select S# from A where Sn like '李%');
delete * from A where Sn like '李%';
5.
select S#,Sex,Age from A where Sn='劉華';
6.
select A.S#,B.C#,B.Cn from A,B,C
where A.Dept not in('計算機系','法律系') and A.S#=C.S# and C.C#=B.C#;
7.
select C.S#,sum(Grade) G from B,C
where Cn='大學語文' and B.C#=C.C# group by C.S# order by G desc;
8.
alter table A drop column Sex;//刪除列
alter table A drop Column Age;
update A set SEX='',AGE='';//刪除列記錄
(不知道你這個刪除具體是什麼意思,2種你自己選擇。)
9.
drop table C;
drop table B;
drop table A; //先刪C再刪A,否則會報錯,無法刪除使用記錄。
7. 【資料庫考試】sql查詢語句,請進
定語
供應工程J1
零件為紅色的
名詞
1. 工程號JNO
8. 求sql資料庫考試題答案
1.create database Readbook
on
(name=Readbook_data,filename='D:\server\Readbook_data.mdf',size=2mb,maxsize=10mb,filegrowth=1mb)
log on
(
name=Readbook_log,
filename='D:\server\Readbook_log.ldf',size=1mb,maxsize=5mb,filegrowth=1mb
)
go
2.use mybase
go
alter database mybase
add log file
(
name=Readbook2_log,
filename='D:\server\mybase2_log.ldf',size=2mb,maxsize=10mb,filegrowth=1mb
)
go
3.alter database mybase
remove file Readbook2_log
9. SQL期末考試資料庫實訓相關問題
企業信息表:INT :id --序列型主鍵自動生成 。VARCHAR :NO--企業編碼,name--企業名稱,……其它附屬信息全部用VARCHAR自己定義把,例如聯系方式,地址,聯系人,所屬地區,備注等等,我只告訴你關鍵信息。
電價流水信息表:INT :id --序列型主鍵自動生成,企業信息表_ID外鍵,---企業信息表ID, DATE--日期,double:電量,電費,
電價單價表:INT :id --序列型主鍵自動生成,企業信息表_ID外鍵--企業信息表DI,
日期:年月,double:單價。這個你可以不寫,但是我們建模型這個基本都做。
2.,存儲過程頭你自己寫 ,監控電價單價表的添加和修改動作,自己照書操。
SQL: update 電價流水信息表 set 電價流水信息表.電費=電價流水信息表.電量*電價單價表.單價 from 電價單價表 where 電價流水信息表.企業信息表_ID=電價單價表. 企業信息表_ID and
格式化 電價流水信息表。日期為年月=電價單價表.日期
就是更新來源是電價單價表,通過2個關鍵詞更新,一個是企業信息ID,一個是格式化後的日期:年月
3.命名一個變數,查詢的時候sum 電量和電費,group by 企業名稱,where 裡面企業名稱=這個變數,
4.其實第三個會寫了 ,第四個 應該跟第三個一樣啊,只是定義了2個參數,一個是地區一個是年份,我告訴你分月統計的方法,查詢裡面sum的時候 格式化流水表的日期為 年月格式,GROUP BY 也要包含這個格式化,然後where裡面寫 格式化日期為年=參數的年
10. sql資料庫任務驅動期末考試
java操作資料庫,沒找到驅動一般有兩個原因:
沒有導入jar包,比如連接Oracle資料庫,就需要導入Oracle官方提供的驅動包。
載入驅動的時候,Class.forName(String str)中的str寫錯了。