CREATE VIEW … AS or INSERT INTO; otherwise, a no operator error will occur.SELECT Fields to select, separated with commasFROM Data source or viewWHERE Filter conditionOther subqueries
SELECT s1.time_, s1.client_ip, s1.uri, s1.protocol_version, s2.status_code, s2.date_FROM KafkaSource1 AS s1, KafkaSource2 AS s2WHERE s1.time_ = s2.time_ AND s1.client_ip = s2.client_ip;
WHERE to filter the data to select from. Combine multiple filter conditions with AND or OR. When a TencentDB table is joined, only AND is supported. To use OR, see UNION ALL below.HAVING to filter the result of GROUP BY. WHERE filters data before GROUP BY, while HAVING filters data after GROUP BY.SELECT SUM(amount)FROM OrdersWHERE price > 10GROUP BY usersHAVING SUM(amount) > 50
GROUP BY arranges query results into groups. It supports GROUP BY with a time window and GROUP BY without (continuous query).GROUP BY with a time window does not update previous results and therefore generates append (tuple) data streams. Such data can only be written to MySQL, PostgreSQL, Kafka, and Elasticsearch sinks that do not have a primary key.GROUP BY without a time window updates previously sent records and therefore generates upsert data streams. Such data can be written to MySQL, PostgreSQL, and Elasticsearch sinks with a primary key (the primary key must be identical to the upsert field in the GROUP BY statement).GROUP BY with a time windowGROUP BY query with a time window. For details about time window functions, see Time Window Functions.SELECT user, SUM(amount)FROM OrdersGROUP BY TUMBLE(rowtime, INTERVAL '1' DAY), user
proctime(). The same is true for HOP and SESSION.GROUP BY without a time window (continuous query)GROUP BY query without a time window. This is known as a continuous query. It determines whether to update previously sent results depending on each arriving data record and therefore generates an upsert stream.SELECT a, SUM(b) as dFROM OrdersGROUP BY a
Equi-JOIN. That is to say, the JOIN query must include at least one filter condition that equates a field in the left and right tables.JOIN with a time range and JOIN without a time range. The former generates append (tuple) streams, while the latter generates upsert streams.JOIN query with a time range is also known as interval join. The WHERE clause of such queries must have at least one equality join condition and a time range. The time range can be specified using <, <=, >=, > or BETWEEN … AND.ltime = rtimeltime >= rtime AND ltime < rtime + INTERVAL '10' MINUTEltime BETWEEN rtime - INTERVAL '10' SECOND AND rtime + INTERVAL '5' SECOND
SELECT *FROM Orders o, Shipments sWHERE o.id = s.orderId ANDo.ordertime BETWEEN s.shiptime - INTERVAL '4' HOUR AND s.shiptime
SELECT *FROM Orders INNER JOIN Product ON Orders.productId = Product.id
JOIN query will follow the order of tables in the FROM clause. This may result in high state pressure and cause the query to fail.SELECT *FROM Orders LEFT JOIN Product ON Orders.productId = Product.idSELECT *FROM Orders RIGHT JOIN Product ON Orders.productId = Product.idSELECT *FROM Orders FULL OUTER JOIN Product ON Orders.productId = Product.id
SELECTo.amout, o.currency, r.rate, o.amount * r.rateFROMOrders AS oJOIN LatestRates FOR SYSTEM_TIME AS OF o.proctime AS rON r.currency = o.currency
FOR SYSTEM_TIME AS OF clause, without which the JOIN query will still be executed, but the database will be read in its entirety only once, and the result may not meet expectations.JOIN query. The syntax is similar to other JOIN queries. You just need to put the UDTF in LATERAL TABLE( ).SELECT users, tagFROM Orders, LATERAL TABLE(unnest_udtf(tags)) t AS tag
SELECT users, tagFROM Orders LEFT JOIN LATERAL TABLE(unnest_udtf(tags)) t AS tag ON TRUE
Left Outer JOIN with UDTFs only supports ON TRUE, which is similar to CROSS JOIN.tags is a defined array.SELECT users, tagFROM Orders CROSS JOIN UNNEST(tags) AS t (tag)
UNION ALL combines the results of two queries.SELECT *FROM ((SELECT user FROM Orders WHERE a % 2 = 0)UNION ALL(SELECT user FROM Orders WHERE b = 0))
UNION ALL and not UNION. That is, it does not remove duplicate rows.DISTINCT together with UNION ALL. DISTINCT converts append (tuple) streams into upsert streams and therefore can only use MySQL, PostgreSQL, and Elasticsearch sinks that have a primary key.OVER to aggregate data streams based on hopping windows (without using GROUP BY). In the OVER clause, you can specify the partition, order, and window frame.amount) for a window size of 3. To specify the number of preceding rows, use PRECEDING. FOLLOWING is not supported currently.ORDER BY. In the example below, the proctime field declared in the data source is used.SELECT SUM(amount) OVER (PARTITION BY userORDER BY proctimeROWS BETWEEN 2 PRECEDING AND CURRENT ROW)FROM Orders
SELECT COUNT(amount) OVER w, SUM(amount) OVER wFROM OrdersWINDOW w AS (PARTITION BY userORDER BY proctimeROWS BETWEEN 2 PRECEDING AND CURRENT ROW)
ORDER BY sorts query results. By default, it sorts the data in ascending order (ASC). You can also use DESC to sort the data in descending order.PROCTIME), in ascending order. After that, you can specify your own fields to sort by.SELECT *FROM OrdersORDER BY `orderTime`, `username` DESC, `userId` ASC
DISTINCT removes duplicates from query results. It should be added after SELECT.SELECT DISTINCT users FROM Orders
DISTINCT generates upsert streams, so you need to use sinks that accept upsert streams. Please note that continuous use of such queries may result in high memory usage.IN keyword to determine whether an element exists in a specified set, such as a subquery.SELECT user, amountFROM OrdersWHERE product IN (SELECT product FROM NewProducts)
EXISTS has one or more rows (data exists), true is returned.SELECT user, amountFROM OrdersWHERE product EXISTS (SELECT product FROM NewProducts)
ORDER BY sorts data by a specified field.SELECT *FROM OrdersORDER BY orderTime
Grouping Sets, Rollup, and Cube generate upsert streams. Therefore, you need to use data sinks that accept upsert streams.SELECT SUM(amount)FROM OrdersGROUP BY GROUPING SETS ((user), (product))
MATCH_RECOGNIZE performs pattern recognition on an input stream, allowing you to use a SQL query to describe complex event processing (CEP) logic.SELECT T.aid, T.bid, T.cidFROM MyTableMATCH_RECOGNIZE (PARTITION BY useridORDER BY proctimeMEASURESA.id AS aid,B.id AS bid,C.id AS cidPATTERN (A B C)DEFINEA AS name = 'a',B AS name = 'b',C AS name = 'c') AS T
name field equates a, b, and c. PATTERN specifies the trigger rule. In the example, the trigger rule is when A, B, and C occur consecutively. MEASURES specifies the output format.Top-N gets the N smallest or largest values from a data stream. It generates upsert streams, so you need to use data sinks that accept upsert streams.Feedback