SQLite (3)-data query

Prior to query data, to understand SQL operators, primarily for use to be a foreshadowing Where sub-query statement, this operator is similar to the java, is better understood, into 算术运算符, , 比较运算符, 逻辑运算符, 位运算符mainly to understand the next logical operators, other The operator is very similar to java.

We use Wheresub-statements to query and obtain data. Generally, where clauses are used after select, delete, and update statements to filter and filter data that meets the conditions.

For example, if we query all the data in the following table, we can select * from user;query through SQL statements.

If we want to query and retrieve all data with age greater than 30, we can use selectand wherecooperate with the query, combined with the comparison operator (>).

If you want to query all data with age greater than or equal to 25 and wage greater than or equal to 10000, you must use comparison operators (>=) and logical operators (and)

If you want to query all data with age less than 30 or wage greater than or equal to 20000, use comparison operators (<, >=) and logical operators (or)


For example, our commonly used search function is realized through the combination of logical operators (like) and wildcards. The wildcards mainly include the following two

  • Percent sign (%)
  • Underscore (_)

The percent sign (%) represents zero, one or more digits or characters. The underscore (_) represents a single number or character. These symbols can be used in combination.

The following demonstrates an example with wildcard characters and Like clause:

  • where user like '200%': Find any value starting with 200
  • where user like'%200%': Find any value that contains 200 at any position
  • where user like'_00%': Find any value where the second and third digits are 00
  • where user like '2_%_%': Find any value that starts with 2 and is at least 3 characters in length
  • where user like'%2': Find any value ending in 2
  • where user like'_2%3': Find any value whose second digit is 2 and ends with 3
  • where user like '2___3': Find any value that has a length of 5 digits and starts with 2 and ends with 3

For example, now we want to query all data whose age field in the table contains 3 or 5.

Guess you like

Origin blog.csdn.net/hzw2017/article/details/84553931