SQL常用條件查詢語句

2021-07-29 13:55:51 字數 1566 閱讀 7915

select * from table1 where 工資》2500 and 工資<3000 //同上

select 姓名 from table1 where 性別='0' and 工資='4000'

select * from table1 where not 工資= 3200

select * from table1 order by 工資desc //將工資按照降序排列

select * from table1 order by 工資 asc //將工資按照公升序排列

select * from table1 where year(出身日期)=1987 //查詢table1 中所有出身在1987的人

select * from table1 where name like '%張' /'%張%' /'張%' //查詢1,首位字『張』3,尾位字『張』2,模糊查詢

select * from table1 order by money desc //查詢表1按照工資的降序排列表1 (公升序為asc)

select * from table1 where brithday is null //查詢表1 中出身日期為空的人

use 資料庫(aa) //使用資料庫aa

create bb(資料庫) //建立資料庫bb

create table table3 ( name varchar(10),*** varchar(2),money money, brithday datetime)

//建立乙個表3中有姓名,性別,工資,出身日期 (此表說明有四列)

insert into table3 values ('張三','男','2500','1989-1-5')//在表中新增一行張三的記錄

alter table table3 add tilte varchar(10) //向表3 中新增一列「title(職位)」

alter table table3 drop column *** //刪除table3中『性別』這一列

drop database aa //刪除資料庫aa

drop table table3 //刪除表3

delete * from table3 //刪除table3 中所有的資料,但table3這個表還在

delete from table1 where 姓名='倪濤' and 日期 is null

delete from table1 where 姓名='倪濤' and 日期='1971'

select * into table2 from table3 //將表3中的所有資料轉換成表2 (相當於複製)

update table3 set money=money*1.2 //為表3所有人工資都增長20%

update table3 set money=money*1.2 where title='經理' //為表3中「職位」是經理的人工資增長20%

update table1 set 工資= 5000 where 姓名='孫八' //將姓名為孫八的人的工資改為5000

update table1 set 姓名='敬光' where 姓名='倪濤' and 性別=1 //將性別為男和姓名為倪濤的人改為敬光

SQL語句多條件查詢

sql多條件查詢中如果有and和or,and的優先順序高於or,如果不加括號會先執行and,然後再執行or 資料表 一 查詢時先且查詢,則先and條件查詢,查詢結果與or後面的條件進行或查詢 sql語句 select from ceshi where name a and age 10 or 1查詢...

條件複雜的sql語句查詢

有三張表 分別為 會員表 member 銷售表 sale 退貨表 regoods 會員表有字段 memberid 會員id,主鍵 credits 積分 銷售表有字段 memberid 會員id 外來鍵 購買金額 mnaccount 退貨表中有字段memberid 會員id 外來鍵 退貨金額 rmna...

SQL語句(八)按條件查詢

select from student select sclass,snumb,sname from student 物理班有哪些同學 年齡小於20歲的有哪些同學?定價在30元以下的計算機書有哪些?sname 張三 sname 張三 snumb 10001 sbirthday 1996 01 01 ...