sqlite

One: optimization of select 1 and select 0
When we only care about how many rows there are in the data table and don’t need to know the specific field values, something like “select 1 from tblName” is a very good SQL statement, which is usually used for subclasses. Inquire. This can reduce system overhead and improve operating efficiency, because the SQL statement written in this way, the database engine will not retrieve the specific records in the data table and the specific field values ​​in each record and put them in memory Instead, output how many "1"s according to how many rows exist in the query. Each "1" represents 1 row of records. At the same time, the number 1 is selected because it occupies the smallest memory space. Of course, the effect of using the number 0 Same thing. This way of writing is definitely preferable when you don't need to know what the specific record value is.
1) List the number of students in each class.
Conventional writing
select class,count (*) as pax from students group by class;
better writing
select class,count (1) as pax from students group by class;

2) List each The data of the youngest students in each class The
conventional writing method
select a.* from students a where not exists(select b.sid from students b where b.sid=a.sid and b.date_birth>a.date_birth);
better writing method
select a.* from students a where not exists(select 1 from students b where b.sid=a.sid and b.date_birth>a.date_birth);
exists cannot be used in sqlite

Second:
pit method: execSQL(String sql) The method cannot write special characters, such as: ',

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324635139&siteId=291194637
Recommended