SQL語句

發表於2008年08月02日 12:46 閱讀(8) 評論(0)

 

1.select
SELECT * FROM chinese ;
SELECT name as 姓名 FROM chinese ;
SELECT * FROM chinese c where age between 18 and 30;

SELECT * FROM test1 t where realist = false and interesting is not null;

SELECT * FROM test1 t where realist = false or interesting is not null;
SELECT * FROM chinese c where name like '%黃%' order by name asc;   //升序
SELECT * FROM chinese c where name like '%黃%' order by name desc;  //%任意字符串
SELECT * FROM chinese c where phone like '55_' order by name desc;  //_任一字符
SELECT count(*) as '記錄數' FROM chinese c;     //計下有幾條記錄
SELECT count(age) as 'ageNO' FROM chinese c;    //計下記錄中age不爲空的數目
SELECT sum(age) as '全部人總年齡' FROM chinese c;  //求age字段的值總和
SELECT avg(age) as '平均年齡' FROM chinese c;     //總和 / !非空值!記錄數
SELECT max(age) as '最大年齡' FROM chinese c;
SELECT min(age) as '最小年齡' FROM chinese c;
2.insert
insert into test2 (name,phone) values ('zhaozhao','13222445566');
3.update
update test3 set phone = '13912345678' where name = 'zhaozhao1'
4.delete
delete from test3 where phone = '13912345678'         //刪除記錄集 ,系"集"
delete from test3      //刪除表中所有記錄

5.drop
drop table test3      //刪除表
6.create

create table test3 ( UserId char(5),name char(20),phone char(20),Userright boolean,primary key(UserId) )

      //primary key    定義主鍵

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章