A. mysql資料庫查詢圖書表,輸出每一類圖書的最高價格、最低價格平均價格的代碼怎
1、首先在mysql資料庫,創建一張data表,表內插入多條數據,用於測試。
B. sql語句查詢(圖書借閱)
1. 借書學生的學生編號會出現在borrow表裡面。
select stuID,stuName,major
from student
where stuID in
(
select stuID from borrow
)
2. 未規還的記錄B_time欄位應該是NULL值。
select stuname,count(*) as 借書數量
from student as a join borrow as b
on a.stuid=b.stuid
where b.B_time is NULL
group by b.stuid,a.stuname
3. select stuname,T_time,
(case when B_time is null then '尚未歸還' else cast(datediff(day,T_time,B_time) as varchar(5)) end) as 借閱天數
from student a join borrow b
on a.stuid=b.stuid
join book c
on b.bookid=c.bookid
where bookname='天龍八部'
我自己測試過,符合要求,你再看看,希望對你有幫助,互相學習~
C. 用SQL語句,查找這樣的圖書類別,要求類別中最高的圖書定價不低於全部按類別分組的圖書平均定價的2 倍
select 圖書類別
from 圖書表
group by 圖書類別
having max(定價)>= all(select avg(定價)*2 from 圖書表 group by 圖書類別)
D. [SQL]求查詢語句T-SQL代碼!關於圖書管理系統的!
1.
while @c<@t
begin
if @rnttime>@borrtime
@count=@count+1
@c=@c+1
end
if @count>5
print'不能借書!'
2.
select p.pubname, avg(b.price) average_price
from publisher p, book b
where p.pubid = b.pubid
3.
你的表裡面沒有定義過期日期,只有借出日期和返還日期,怎麼判斷過期未還?
E. 編寫SQL語句,查詢圖書表中不是科學出版社出版的圖書的全部信息
語句:select *
from 圖書表
where 出版社 <> '科學出版社'
看你好像不太會否定語句,其實就知道兩點就夠了。
用否定的時候只能是和Like、in、between一起使用
比如 欄位1 Not in (1,3,5)
其他的邏輯比較的話都有相反的比較方法,
比如=和<>,>和<=等等,具體要看實際需求的
回答不易,望採納~
F. SQL 圖書管理系統的查詢語句
1. 求總藏書量、藏書總金額,總庫存冊數、最高價、最低價。
select count(圖書編號) as 總藏書量,
sum(定價) as 藏書總金額,
sum(實際數量) as 總庫存冊數,
max(定價) as 最高價,
min(定價) as 最低價
from 圖書卡片
go
2. 列出藏書在10本以上的書(書名、作者、出版社、年份)。
select 圖書名稱,作者姓名,出版社,出版日期
from 圖書卡片
group by 圖書編號 having(coung(1)>10)
order by 圖書名稱
go
3. 哪些出版社的藏書種類數超過100種。
select 出版社 as '藏書種類數超過100種的出版社'
from 圖書卡片
group by 出版社 having(count(類別)>100)
order by 出版社
go
4. 目前實際已借出多少冊書?
select sum(借出數量) as '借出數量'
from 圖書卡片
go
5. 年份最久遠的書。
select top 1 with ties 圖書名稱 from 圖書卡片
order by 出版日期
go
6. 「資料庫系統原理教程,王珊編,清華大學出版社,1998年出版」還有幾本?
select count(1) from 圖書卡片
where concaints(摘要,'"資料庫系統原理教程,王珊編,清華大學出版社,1998年出版"')
go
7. 哪一年的圖書最多?
select top 1 with ties convert(substring(出版日期,1,4)) as 年份,count(1) as '圖書數量'
from 圖書卡片
group by 出版日期
order by 圖書數量 desc
go
8. 哪本借書證未歸還的圖書最多?
select top 1 with ties A.讀者編號,count(1) as '借書數量'
from 圖書卡片 A,借閱 B
where A.圖書編號=B.圖書編號
group by A.讀者編號
order by 借書數量 desc
go
9、平均每本借書證的借書冊數。
select avg(借閱數量) as '平均每本借書證的借書冊數'
from 借閱
go
10.哪個系的同學平均借書冊數最多?
select top 1 with ties A.工作單位,avg(借閱數量) as '平均借閱數量'
from 讀者 A,借閱 B
where A.讀者編號=B.讀者編號
group by A.工作單位
order by 平均借閱數量' desc
go
11. 最近兩年都未被借過的書。
select 圖書名稱
from 圖書卡片
where 圖書編號 in(select 圖書編號 from 借閱 where datediff(year,借閱日期,getdate())>2)
go
12. 列出那些借了圖書逾期未歸還的借書證號和圖書名。
select A.讀者編號 as '借書證號',B.圖書名稱
from 讀者 as A inner join 圖書卡片 as B on A.圖書編號=B.圖書編號
where A.應歸還日期<getdate() and A.實際歸還日期 is null
go
13.今年未借過書的借書證。
select 讀者編號
from 讀者
where 讀者編號 not in(select 讀者編號
from 讀者
where datediff(year,借閱日期,getdate())=0)
go
14. 今年那種書出借最多?
select top 1 with ties A.類別,count(1) as '借出數量'
from 圖書卡片 A,借閱 B
where datediff(year,B.借閱日期,getdate())=0
group by A.類別
order by 借出數量' desc
go
G. 設計圖書管理系統sql查詢語句
1
SELECT *
FROM C
WHERE C# IN(SELECT C# FROM SC GROUP BY C# HAVING COUNT(*) BETWEEN 2 AND 4)
2
SELECT S#
FROM SC JOIN C ON SC.C#=C.C#
WHERE CN='計算機基礎'
GROUP BY S#
HAVING COUNT(*)>=2
H. SQL 圖書館系統資料庫觸發器代碼
1、---------------這是分割線--------------------------
Create Trigger tg_借書觸發器名 on [借閱記錄] For Insert
as
update [借閱記錄] set [借閱記錄].借書日期=getdate(), [借閱記錄].應還日期=getdate()+[讀者].可借天數
from [借閱記錄] inner join [讀者] on [借閱記錄].讀者卡號=[讀者].讀者卡號
where [借閱記錄] in(SELECT [借閱記錄] FROM INSERTED)
update [圖書] set [圖書].在庫數量=[圖書].在庫數量-1
where [圖書].圖書號 in (select 圖書號 from Inserted)
update [讀者] set [讀者].可錯數量=[讀者].可錯數量-1
where [讀者].讀者卡號 in (select 讀者卡號 from Inserted)
2、--------------------這是分割線--------------------------------
create trigger tg_還書觸發器名 on [借閱記錄] For Update
as
update [圖書] set [圖書].在庫數量=[圖書].在庫數量+1
where [圖書].圖書號 in (select 圖書號 from Deleted)
update [讀者] set [讀者].可錯數量=[讀者].可錯數量+1
where [讀者].讀者卡號 in (select 讀者卡號 from Deleted)
--超期時插入到超期記錄表
if(select 1 from Deleted where 應還日期<getdate())
begin
--insert into 超期記錄表(編號,讀者卡號,超期天數,超期金額) values(…………)
-----題目中沒給出超期金額演算法,編號應該是自動不應該手動插入。
end
3、---------這是分割線--------------------
create trigger tr_插入讀者觸發器名 on [讀者] For Insert
as
if(select 1 from Inserted where 類型='學生')
begin
update [讀者] set 可借天數=30 where 讀者卡號 in(select 讀者卡號 from Inserted)
end
else
begin
update [讀者] set 可借天數=60 where 讀者卡號 in(select 讀者卡號 from Inserted)
end
注釋:觸發器語句中使用了兩種特殊的表:deleted 表和 inserted 表。
Deleted 表用於存儲 DELETE 和 UPDATE 語句所影響的行的復本。在執行 DELETE 或 UPDATE 語句時,行從觸發器表中刪除,並傳輸到 deleted 表中。Deleted 表和觸發器表通常沒有相同的行。
Inserted 表用於存儲 INSERT 和 UPDATE 語句所影響的行的副本。在一個插入或更新事務處理中,新建行被同時添加到 inserted 表和觸發器表中。Inserted 表中的行是觸發器表中新行的副本。
I. 用SQL語句實現查詢表名為「圖書表」中的所有記錄所有欄位,應該使用的SELECT語句是什麼()
select * from 圖書表
J. 顯示"圖書"數據表中的所有記錄 SQL語句怎麼寫
select * from 圖書