標籤:
--建立表
第一種方式
create table t_hui(
id integer,//
name text,
sex text,
//第一個參數為要建立的欄位名,第二個參數為欄位的類型
)
第二種方式
create table t_hui(
id integer,// primary key autoincrement //設定id為主鍵,並且自增加
name text, unique //unique 代表該欄位的值只能是唯一的,不能有重複
sex text, not null default 20 // not null 代表不可為空,default 20 代表預設值為20
//第一個參數為要建立的欄位名,第二個參數為欄位的類型
)
--插入資料
INSERT INTO t_hui (name,age,sex) values (‘是‘,18,‘父‘)//向指定的地欄位添加資料
INSERT INTO t_hui values (‘是‘,18,‘父‘)//向所有欄位添加資料,有幾個欄位就添加幾個值,不然會報錯
--修改資料
UPDATE t_hui set name = ‘惠‘,age = 20 //文法 UPDATE t_hui set 欄位1= ‘惠‘,欄位2= 20
--刪除資料
DELETE from t_hui //刪除表內所有資料
DELETE from t_hui where name = ‘小龍女‘ //指定刪除t_hui表裡面name欄位為小龍女的資料
--排序查詢
select from t_hui order by age //查詢t_hui表內age的資料,並且對他進行升序排序,desc是降序
--求和
select avg(age) from t_hui //求平均值t_hui表內age的資料
select max(age) from t_hui //求最大值t_hui表內age的資料
select age from t_hui where age in(1,3,4,5,67,7)//查詢多個數值
--LIKE操作符
select from t_hui where name ‘%惠‘//篩選以惠為結尾的資料
select from t_hui where name ‘%惠%‘//篩選有惠的資料
select from t_hui where name ‘惠%‘//篩選以惠為開頭的資料
--分頁查詢
select from t_hui limit 0,8 //從0之後開始查詢,查詢數量為8個,
select * from t_hui p join t_tao s on s.id = p.id //聯集查詢
//join 是把兩個表聯合到一起,on是聯集查詢的id
Android進階-SQL語言