SQL query

更新时间:
复制 MD 格式

The SQL query feature provides a unified interface to access multiple data engines. You can use this feature to run complex queries and perform efficient analysis on data in Tablestore. In Internet of Vehicles (IoV) scenarios, the SQL query feature acts as a unified interface to query different types of data.

Note

For more information about SQL query, see SQL query.

Overview

The SQL query feature is compatible with MySQL query syntax. It also provides basic SQL Data Definition Language (DDL) capabilities to create tables. For existing data tables, you can run the CREATE TABLE statement to automatically create a mapping. You can then use SQL to access the data in the table.

The SQL query feature supports search indexes to quickly query data that meets specified conditions. When you use the SQL query feature, the system automatically selects an appropriate method to accelerate SQL access.

The SQL query feature is suitable for online data access scenarios that involve massive datasets. The latency of SQL access ranges from milliseconds to minutes. This includes point queries based on the primary keys of data tables (GetRow operations), term queries based on search indexes (TermQuery), and queries that use the statistical aggregation capabilities of search indexes, such as counting the number of rows that meet a condition or calculating the sum of a column.

SQL examples

Note
  • For the schema of the `vehicles_metadata` data table, see Table schema.

  • Before you run an SQL query, you must create a mapping for the table. For more information, see Create a table mapping.

  • You can query the locations of vehicles with a current speed greater than 80.0 km/h and an emission value greater than 2.0 mg.

    select vin_id,gps from `vehicles_metadata` where speed > 80.0 and bms_soc > 2.0 limit 10;
  • Find information about vehicles in Hangzhou, Zhejiang Province.

    select vin_id from `vehicles_metadata` where TEXT_MATCH(license_plate_number, "ZheA");
  • Count the total number of vehicles in Hangzhou, Zhejiang Province.

    select count(*) from `vehicles_metadata` where TEXT_MATCH(license_plate_number, "ZheA");

Use SQL query

You can use the SQL query feature in the following ways:

FAQ