Android進階-SQL語言

來源:互聯網
上載者:User

標籤:

--建立表

第一種方式

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語言

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.