簡單常用sql查詢

2022-07-14 17:15:11 字數 1940 閱讀 4966

[self.db

executeupdate:sql, record.recordid];

create table scene_record(id text primary key, record_time text, location text,place text,description text,isupdate text,is_delete text)

按生序查詢,並指定查詢值

select * from scene_record where isupdate = 1 or isupdate = 2 order

by record_id asc

按降序排列

select * from scene_record where isupdate = 1 or isupdate = 2 order

by record_id desc

條件查詢

select * from scene_record where isupdate = 1 or isupdate = 2

未指定查詢值

select * from scene_record where name=?

查詢最大id

select max(id) from scene_record

從搜尋結果中搜尋

select * from info_tag where parent_id = (select parent_id from info_tag where id=?)

帶有or的條件搜尋

select * from scene_record_detail where (is_upload = 1 and is_delete = 0) or (is_upload = 2 and is_delete = 0)

插入語句:

插入表中的一列資料

insert into custom_classify (name) values(?)

[self.db

executeupdate:sql,classifyname];

插入全部資料:

insert into scene_record values(?,?,?,?,?,?,?)

[self.db

executeupdate:sql,record.recordid,record.recordtime,location, record.place, record.scenerecorddescription, @"1", @"0"];

插入指定列:

insert into scene_record (record_id,record_time,location,place,description,isupdate,is_delete) values(?,?,?,?,?,?,?)

[self

.dbexecuteupdate

:sql,record.recordid,record.recordtime,record.location,record.place,record.scenerecorddescription,

@"2"

,@"0"

];更新語句:

根據record_id更新一列is_delete

update scene_record set is_delete = 1 where record_id = ?

[self.db

executeupdate:sql, record.recordid];

根據record_id跟新多列location,place,description,isupdate

update scene_record set location = ?, place = ?, description = ?, isupdate = 1 where record_id = ?

刪除語句:

刪除全部:

delete from test_table

ps:注意這裡沒有*

SQL 簡單的查詢常用套路

1.在查詢的時候,如果是有兩個並且的條件的時候,比如 查詢同時參加語文考試和英語考試的人資訊,這個人要同時參加了兩門學科的查詢,這裡不能直接使用and來做拼接,如果直接是 學科 語文 and 學科 英語 表現出來的效果是在這一條記錄中此字段要既是語文又是英語,這是不可能的,是查詢不到資料的,但是並且...

sql常用查詢

insert into t call callnumber,tellnum,startdatetime,enddatetime values 13925473495 gzsx009 2013 10 20 10 03 2013 10 22 13 06 輸出所有資料中通話時間最長的5條記錄。用order...

常用SQL查詢指令碼

本文假定讀者已經對資料庫連線技術有所了解,因此只討論有關sql查詢命令的語法。表結構如下 ms access 2000 表名 usertable 欄位名 字段型別 userid 自動計數 長整型 username 文字 user 文字 createdate 日期 時間 預設值為now 一 用sele...