#import "table.h"
@implementation table
// 1.創建表 每列之間用',',如果存在就不創建
create table if not exists t_class(
class_id integer primary key autoincrement,
class_name varchar,
person_count integer default 0)
// 1.1// 刪除表
drop table if exists t_person
// 2.插入數據(增),由于設置id為自增,所以不輸入直接為1
insert into t_class (class_name,person_count) values('class1',10)
// 3.刪除數據(刪)
// table里的全刪 deleta from t_class
// 刪除指定id=5的數據 delete from t_class where class_id=5
// 4.修改數據
name全改成newclassname update t_class set class_name='newclassname'
修改某1行的某個數據 update t_class set class_name='newclassname' where class_id=7
// 5.查詢數據(查)
查詢所有 select * from "t_class"
查詢指定1個或幾個數據 select class_id,person_count from t_class where class_name='oldname'
關鍵字 and or
select class_id,person_count from t_class where class_id=7 and person_count=20
select class_id,person_count from t_class where class_id=7 or person_count=20
select class_id,person_count from t_class where class_id between 7 and 20
// in like不需要非要查主鍵
select class_id,person_count from t_class where class_id in(7,9) // 在7和9的
select class_id,person_count from t_class where class_id not in(7,9)// 不在7和9的
select class_id,person_count from t_class where class_name like 'new%' //以new開頭
select class_id,person_count from t_class where class_name like '%class' // 以new結尾
// 獲得表的數據總數 在count(*)后面加名字可以起別名
select count(*) number from t_class // count1是按第1列來統計,1般以主鍵列統計1般寫*就能夠
// 獲得最小值
select min(person_count) from t_class
// 獲得最大值
select min(person_count) from t_class
// 獲得平均值
select avg(person_count) from t_class
// 獲得總成績
select sum(person_count) from t_class
// 獲得絕對值
select abs(person_count) from t_class
// 在不修改數據的條件下查詢結果去除前后空格
select trim(class_name) from t_class
// 替換
select replace(class_name,'c','o') from t_class
// 長度(空格也算長度)
select length(class_name) from t_class
// 日期函數
select date() from t_class
select datetime() from t_class
// 判斷為空
select * from t_class where class_name is null
// 排序
select * from t_class order by class_id desc (倒序)
select * from t_class order by class_id asc (正序、asc可省默許正序)
@end
上一篇 poj逗比了...