新建資料庫名為book
create database book;
2)建一張表:圖書表(book)
create table book( book_id int pk,book_name varchar(20),book_price double,
book_author varchar(20), book_desc varchar(100),tid int );
book_id (圖書id,主鍵) book_name (圖書名稱) book_price (圖書**)
book_author (圖書作者) book_desc (圖書描述) tid (分類id) 外來鍵
表二:分類表(type)
create table type(type_id int pk,type_name varchar(20));
type_id (分類id) 主鍵 type_name (分類名稱)
select * from book,type where book.tid = type.type_id;
3)兩表聯查,查詢出所有的圖書資訊
select book.*,type.* from book,type where book.tid = type.type_id;
4)查詢出**分類下的所有圖書資訊
select book.* from book,type where book.tid = type.type_id
and type.type_name = '**';
5)將圖書**在10到20之間的圖書名稱修改為西遊記
update book set book_name = '西遊記' where book_price between 10 and 20;
6)查詢出圖書名稱或者圖書描述中包含有aaaa的圖書資訊
select * from book where (book_name like '%aaaa%' or book_desc like '%aaaa%');
7)出分類名稱是名著或者作者姓張的圖書資訊
select book.* from book,type where book.tid = type.type_id
and (book.book_author like '張%' or type.type_name = '名著');
8)將張三發布的圖書資訊刪除
delete from book where book_author = '張三';
9)查詢出最貴的三件圖書資訊
select * from book where order by book_price desc limit 0,3 ;
10)將圖書作者中包含」三「或者商品**在2元以上的圖書名稱修改為紅樓夢
update book set book_name = '紅樓夢' where (book_author like '%三%' or book_price > 2);
11)查詢出圖書單價在6元以上且分類名稱是散文的圖書資訊,從第3條取,取5條
select book.* from book,type where book.tid = type.type_id
and (book.book_price > 6 and type.type_name = '散文') limit 2,5;
12)查詢出圖書名稱為「水滸傳」的分類為名著的圖書資訊
select book.* from book,type where book.tid = type.type_id
and book.book_name = '水滸傳' and type.type_name = '名著';
13)將圖書**大於20或者圖書作者包含「王」的圖書資訊刪除
delete from book where (book_price > 20 or book_author like '%王%');
14)查詢出圖書分類屬於傳記,**在5到15之間,姓李的發布的圖書資訊
select book.* from book,type where book.tid = type.type_id
and (type.type_name = '傳記' and (book.book_price between 5 and 15) and book.book_author like '李%' );
15)將圖書名稱中第二個字是」遊「或者單價小於2的圖書描述改為「aaaaa」
update book set book_desc = 'aaaaa' where (book_name like '_遊' or book_price < 2);
16)查詢出最便宜的圖書資訊,從第2條取10條
select * from book where oder by book_price limit 1,10 ;
17)查詢出圖書分類為散文,圖書**在2到5之間,圖書名稱或者圖書描述包含「中國你好」的最便宜的三件商品
select book.* from book,type where book.tid = type.type_id
and type.type_name = '散文' and book.book_price between 2 and 5
and (book.book_name like '%中國你好%' or book.book_desc like '%中國你好%') order by book.book_price like 0,3;
18)將表資料清空
delete * from book;
java sql語句模糊查詢
dao層使用like對於關鍵字的模糊查詢 今天在做開發的時候需要使用like 對關鍵字進行模糊查詢,可是總是寫不好,多次嘗試發現有許多坑,在此記錄下 錯誤,後面引數實際傳入mysql服務中會變為 string sql select from user where like object obj re...
verilog for 語句例項
1.1要求 實現8位資料低4位左移到高4位 1.2 module move result,in,res,clk input 3 0 in input clk,res output 7 0 result reg 7 0 result integer i always clk or in or res ...
if語句例項優化
輸入兩個實數a b,按數值由小到大的順序輸出這三個數。以下為我初次編寫的 include intmain 聽過猴博士課程解析後了解了其實只需用1個if語句就可以搞定,而無需使用else語句補充,基本思路為先將兩個實數比較大小,若a大,則將a與b的數值交換 從而保證a總是最小的實數,故輸出時先輸出a,...