SQL的基礎查詢案例
表名 表的欄位
Drivers DriversID, DriversName, UnitPrice from Drivers
Expense ExpenseID, ExpenseDate, DrinksID, Num from Expense
Singer SingerID, SingerName, SingerType, Birthday,
Area, PhotoPath from Singer
Song SongID, Title, PingTitle, TypeID, SingerID, Hit, Url from Song
Type TypeID, TypeName from Type
表名與表欄位都給了 ,資料你們自己加進去。
–1.查詢歌手錶中歌手型別為女歌手的資訊,並按出生年月排序
select SingerID, SingerName, SingerType, Birthday,
Area, PhotoPath from Singer where SingerType=‘女’
order by Birthday
–2.查詢歌曲表中點歌次數超過50次的歌曲,並從高至低排序
select SongID, Title, PingTitle, TypeID, SingerID, Hit, Url from Song
where Hit>50 order by hit desc
–3.查詢酒水小食消費表中日期在2013年5月20日至 5月28日的消費資訊
select ExpenseID, ExpenseDate, DrinksID, Num from Expense
where ExpenseDate between ‘2013-05-20’ and ‘2013-05-28’
–4.將歌手地區’臺灣’修改成’台灣’
select SingerID, SingerName, SingerType, Birthday,
Area, PhotoPath from Singer
update Singer set Area=‘中國’ where Area=‘大陸’
–5.查詢歌曲名中包含’曾經’的歌曲資訊.
select SongID, Title, PingTitle, TypeID, SingerID, Hit, Url from Song
where Title like ‘%曾經%’
–6.找到歌手錶中姓名長度大於2的歌手
select SingerID, SingerName, SingerType, Birthday,
Area, PhotoPath from Singer
where len(SingerName)>2
–7.檢視歌手錶中有哪些歌手地區.(去重複顯示單條資訊)
select distinct Area from Singer
–8.查詢出歌手’周杰倫’唱的所有歌曲.
select SongID, Title, PingTitle, TypeID, SingerID, Hit, Url from Song
where SingerID=
(select SingerID from Singer where SingerName=‘周杰倫’)
select SongID, Title, PingTitle, TypeID, Hit, Url from Song,Singer
where Song.SingerID=Singer.SingerID and Singer.SingerName=‘周杰倫’
–9.查詢出2013-5-30消費的酒水小食資訊(要求:顯示酒水小食名稱和價格)
select DriversID, DriversName, UnitPrice from Drivers
select ExpenseID, ExpenseDate, DrinksID, Num from Expense
where ExpenseDate=‘2013-05-30’
select DriversName,UnitPrice*num from Drivers,Expense
where Drivers.DriversID=Expense.DrinksID and ExpenseDate=‘2013-05-30’
–10.查詢出所有‘經典老歌’(要求:where條件必須是歌曲型別表的typename = ‘經典老歌’)
select SongID, Title, PingTitle, TypeID, SingerID, Hit, Url from Song
where TypeID =
( select TypeID from Type where TypeName=‘經典老歌’)
select SongID, Title, PingTitle, SingerID, Hit, Url from Song,Type
where Song.TypeID=Type.TypeID and Type.TypeName=‘經典老歌’
–11.刪除所有屬於’SHE’的歌曲.(要求:where條件後是Singer表的SingerName = ‘SHE’)
delete from Song where SingerID=
(select SingerID from Singer where SingerName=‘SHE’)
–select SongID, Title, PingTitle, TypeID, SingerID, Hit, Url from Song
–where SingerID=
–(select SingerID from Singer where SingerName=‘SHE’)
–12.將2013-5-30日消費記錄中的’開心果’刪除.(要求:where條件後是Drinks表的DrinksName = ‘開心果’)
delete from Expense where DrinksID=
(select DriversID from Drivers where DriversName=‘開心果’)
and ExpenseDate=‘2013-5-30’
–13.算出2013-5-30日的消費總額.
select sum(UnitPrice*num) from Drivers,Expense
where Drivers.DriversID=Expense.DrinksID and ExpenseDate=‘2013-05-30’
相關文章
- Sql介紹 與 Sql基礎查詢SQL
- SQL語言基礎(子查詢)SQL
- SQL基礎的查詢語句烈鉍SQL
- MySQL學習(三) SQL基礎查詢MySql
- SQL語言基礎(高階查詢)SQL
- 【學習】SQL基礎-007-子查詢SQL
- 15個初學者必看的基礎SQL查詢語句SQL
- 【--SQL基礎-->層次化查詢(START BY ... CONNECT BY PRIOR)】SQL
- 資料庫基礎查詢--單表查詢資料庫
- 【學習】SQL基礎-006-多表連線查詢SQL
- 剖析SQL Server 2005查詢通知之基礎篇SQLServer
- MySQL資料庫基礎——多表查詢:子查詢MySql資料庫
- MySQL基礎查詢語句MySql
- mysql查詢表基礎資訊MySql
- Django:查詢基礎語法Django
- SQL查詢的:子查詢和多表查詢SQL
- MSSQL基礎教程:使用SQL子選擇來合併查詢SQL
- SQL 基礎增、刪、改、查SQL
- 效能為王:SQL標量子查詢的優化案例分析SQL優化
- SQL優化之多表關聯查詢-案例一SQL優化
- 01 | 基礎架構:一條SQL查詢語句是如何執行的?架構SQL
- T-SQL進階:超越基礎 Level 2:編寫子查詢SQL
- SQL Server調優系列基礎篇(子查詢運算總結)SQLServer
- 編寫 SQL 查詢:讓我們從基礎知識開始SQL
- ElasticSearch基礎及查詢語法Elasticsearch
- MySQL(三)DQL之基礎查詢MySql
- MSSQL基礎教程:多表格查詢SQL
- 《MySQL 基礎篇》四:查詢操作MySql
- SQL Server:基於WEB的資料庫查詢SQLServerWeb資料庫
- sql查詢案例:刪除2條完全一樣的資料SQL
- (轉)SQL查詢案例:多行轉換為一行SQL
- CDA資料分析師 - SQL資料庫基礎 查詢&連線SQL資料庫
- VC++基礎 字串的查詢與替換C++字串
- Linux基礎命令---查詢程式idLinux
- es 筆記二之基礎查詢筆記
- 基礎二分查詢總結
- MyBatis基礎:MyBatis關聯查詢(4)MyBatis
- javascript基礎(DOM查詢)(二十六)JavaScript