『壹』 sql SEVER的練習題
insert into student values (95019,'於兵','男',18)
select * from student where (專業='計算機')and 姓名 like '張%'
select count(學號) from student
select count(學號) from student where 選修門數>3
select 學號,姓名 from student where 科目='資料庫'and 成績>80 order by 學號
select 學號,姓名 from student group by 學號 having sum(成績)>450
『貳』 sql資料庫練習題,急求!!!
創建一個選擇查詢,按系別統計各自男女學生的平均年齡
SELECT
系,
性別,
AVG(年齡) AS 平均年齡
FROM
表
GROUP BY
系,
性別
上面是用 SQL 的處理方法。
樓主要求 「最好不是SQL啊」, 不知道樓主 希望是用什麼?
一步一步操作?
那要說明是什麼資料庫啊.
如果是 Access的話, 操作順序是這樣的:
1、創建一個查詢
2、在《顯示表》窗口裡面,把那個表 選中,按 添加按鈕。
3、關閉《顯示表》窗口, 進入設計窗口。
4、在表中,雙擊 系, 性別, 年齡 這3列, 加到下面的列表中。
5、在下面列表的地方,滑鼠右鍵,在彈出窗口,選擇 「匯總」
6、修改 年齡下面的 Group By, 變成 「計算」 注意,不是「總計」。
7、運行查詢。
『叄』 關於SQL命令的練習題,急急急!!!
select * from 專業表
select * from 課程表 where ID='000001' order by 成績 desc
select avg(成績) from 成績表 group by 課程 where 人數>1
select count(人數),max(成績),min(成績),avg(成績) from 成績表 group by 課程 where 成績 is not null
select count(課程) from 成績表 group by 學號
sleect * from 學生信息表 join 成績表 on 學號=學號
『肆』 SQL練習題 關系:圖書(書號,書名,作者,出版社,單價) BOOK(Bno, Bname, Author, Press, Price) 查詢「數據
--查詢「資料庫」一書的書號和單價
select bno,price from BOOK where bname='資料庫'
--查詢單價在20至50元之間的圖書信息
select Bno, Bname, Author, Press, Price from book where price between 20 and 50
--查詢北京某出版社出版的圖書信息
select Bno, Bname, Author, Press, Price from book where Press='北京某出版社'
--查詢作者是張一,王二,劉三的書的信息
select Bno, Bname, Author, Press, Price from book where author in('張一','王二','劉三')
--查詢所有圖書的書號,書名和半價信息
select Bno, Bname, Price/2 from book
--查詢缺少出版社信息的圖書的書號和書名
select Bno, Bname from book where Press is null or Press=''
『伍』 SQL資料庫練習題~
1.select name from 學生
where 系別='數學系' and 性別='女';
2.select a.name from 學生 a inner join 選課 b
on a.學號=b.學號
where 成績<60;
3.select a.name from 學生 a inner join 選課 b
on a.學號=b.學號
where avg(成績)>=95;
4.select a.name from 學生 a inner join 選課 b
on a.學號=b.學號
where (select b.成績 from 課程 c inner join 選課 b
on c.課程號=b.課程號 where 課程名='SQL Server 2000')<60
5.update 學生
set 年齡=年齡+1;
『陸』 SQL的練習,求答案!!!
/*創建Moonfox_db資料庫*/
use master
if exists(select * from sysdatabases where name='Moonfox_db')
drop database Moonfox_db
create database Moonfox_db
on
(
name='Moonfox_db_data',
filename='D:\Visual Studio 2008 & Sql server 2005\Sql server\Moonfox_db.mdf',
size=10,
filegrowth=2MB
)
log on
(
name='Moonfox_db_log',
filename='D:\Visual Studio 2008 & Sql server 2005\Sql server\Moonfox_db.ldf',
size=5,
filegrowth=20%
)/*創建Department表*/
use Moonfox_db
if exists(select * from sysobjects where name='Department')
drop table Department
create table Department
(
DID int identity (1,1)primary key,--部門編號,主鍵
Dname nvarchar(20),--部門名稱
Address nvarchar(50),--部門地址
Photo decimal(12,0),--電話
)/*創建Employee表*/
use Moonfox_db
if exists(select * from sysobjects where name='Employee')
drop table Employee
create table Employee
(
EID int identity (1,1)primary key,--職工編號,主鍵
Ename varchar(10),--職工名
Gender nchar(2) check(Gender='男' or Gender='女'),--性別,添加限制
Position nvarchar(10) check(Position='員工' or Position='組長' or Position='經理'),--職務,添加限制
Address nvarchar(50),--家庭地址
DID int,--部門編號,外鍵
foreign key(DID) references Department(DID)--外鍵約束
)
/*創建Care表*/
use Moonfox_db
if exists(select * from sysobjects where name='Care')
drop table Care
create table Care
(
CID int identity (1,1)primary key,--保健卡編號,主鍵
EID int,--職工號,外鍵
foreign key(EID) references Employee(EID),--外鍵約束
CheckDate datetime,--檢查身體日期
PhysicalCondition nvarchar(4) check(PhysicalCondition='一般' or PhysicalCondition='差' or PhysicalCondition='好'),--健康狀況
)
/*創建Care表約束*/
alter table Care
add
constraint DF_CheckDate default(getdate()) for CheckDate--預設,默認凈時間為當前計算機時間 路徑自己修改,試圖自己做,選擇語句自己寫。我該睡覺了,抱歉,你試著在sql server中運行下,我等著休息,也不知道寫的有沒有錯誤,沒時間幫你寫省下的了。不急著用的話我明天幫你寫吧。
『柒』 SQL數據查詢練習
--1.1創建新表 score
create table score
(
[學號] varchar(10)
,[課程號] varchar(10)
,[成績] float
)
--1.2插入新表的值
insert into score values(103,'3-245',86)
insert into score values(105,'3-245',75)
insert into score values(109,'3-245',68)
insert into score values(103,'3-105',92)
insert into score values(105,'3-105',88)
insert into score values(109,'3-105',76)
insert into score values(101,'3-105',64)
insert into score values(101,'3-105',64)
insert into score values(101,'6-166',85)
insert into score values(107,'6-166',79)
insert into score values(108,'6-166',81)
--1.3 按排列順序查看創建的表的內容
select* from score order by [課程號] asc,[成績] desc --這樣查看不舒服,可以修改下,如下面這句:
select [課程號],[成績],[學號] from score order by [課程號] asc,[成績] desc
--1.4
select y=sum([成績]) --查找3-105 的分數之和,問題6-166的總分也是這個道理
, x=count([課程號]) from score where [課程號]='3-105'--查找3-105的課程個數
--計算平均分
select [3-105平均分]=y/x from(select y=sum([成績])
, x=count([課程號]) from score where [課程號]='3-105')t
--1.5 查詢成績為定值的記錄
select * from score where [成績]='85' or [成績]='86' or [成績]='88'
--這里用and 的話沒法查出內容,
--1.6 成績在多少到多少的記錄
select * from score where [成績] between 60 and 79 order by [成績] desc
--1.7查詢每個學生的最高分
select * from score where [成績] in(select max([成績]) from score group by [學號])
--1.8課程最高分
select * from score where [成績] in(select max([成績]) from score group by [課程號])
--各門課程最高分大於90的就是在上面的內容上增加一個where 條件,自己嘗試下
select * from(select * from score where [成績] in(select max([成績]) from score group by [課程號]))t
where [成績]>=90
--注意資料庫別名的用法't'
--1.9弟九個問題跳過,扯蛋的問題
--2.0課程次數及排序
select [課程號],[課程次數]=count([課程號]) from score group by [課程號] order by 課程次數 desc
--注意資料庫自定義欄位的使用
--升序 asc ,降序 desc
--2.1最後一個問題你自己考慮考慮,方法基本都在前面幾個問題裡面可以找到。
『捌』 急求SQL資料庫練習題
樓上的--理論很多不太使用:ㄨinsert -增加語句用法 insert into(Name,Sec)values("張三","李四") --這個語句1.習題:插入學員信息 Name,Sex,Age,Address (地址可為null) 要有自動標識列。 2.實現一次插入多行。3.把原有表中的某個欄位 移到新表中 提示:select <欄位> into newtable from <原表> ㄨdelecte --刪除語句delecte from <表> [where<條件>]例題:上表中 --刪除 年齡是66和地址為null 信息 (年齡與地址自己添加) ㄨupdate--更新語句update set <條件> where[限制條件]例題:把年齡大於50歲的 更新為49歲 其餘條件自己加 ㄨselect --查詢語句select <欄位1>,<欄位2> from <表> where [條件]例題:從表1、表2中查找相同欄位並且 把相同欄位存放到新的表中這里子查詢就不多說了。這些題很基礎你試一試。