SQL 檢視 阿新 • • 發佈:2022-05-27 --檢視是對於一段sql的封裝--檢視其實就是一張表(真實的,虛擬的表) 語句如下: create view a asselect *from stuInfo 查詢 檢視 select *from a; 這樣就省去寫那些程式碼的時間了 create table region( id varchar(20) primary key, --主鍵,區域編號 name varchar(20) not null, --區域名稱 pid varchar(20) not null --區域附屬編號 0省份); insert into region select 's2309','廣東省','0'unionselect 's2098','湖南省' ,'0'unionselect 's2033','廣西省' ,'0'unionselect 's2034','永州市' ,'s2098'unionselect 's2056','長沙市' ,'s2098'unionselect 's2012','廣東市' ,'s2309'unionselect 's2089','東莞市' ,'s2309' unionselect 's2037','懷化市' ,'s2098' --查詢所有的省分select *from region where pid='0' 結果如下: ---- 查詢湖南省下素有的市select *from region where pid='s2098' 結果如下 select *from region where pid in(select id from region where name ='湖南省') 結果如下: select a.name,count(b.name)from region a full join region bon a.id=b.pid where a.name like '%省%'group by a.name; 結果如下: -- 查詢性張的人: 張x,張xx,張xxxselect * from stuInfo where stuName like '張%'; -- 查詢性張的人: 張xxselect * from stuInfo where stuName like '張__'; -- 查詢以麗結尾的人: xx麗select * from stuInfo where stuName like '%麗'; -- 查詢名字帶秋的人: 秋xx,x秋x,xx秋select * from stuInfo where stuName like '%秋%';