query-expr

The query-expr is an SQL SELECT query that returns a table.

Format

SELECT [ TOP ( expression ) [ PERCENT ] ] [ WITH TEMPLATES ] [ ALL | DISTINCT ] { * | select-element [ , select-element ]* )

FROM join-expr

[ WHERE bool-condition ]

[ GROUP BY column-ref [ , column-ref ]* ]

[ HAVING bool-condition ]

Remarks

The SELECT clause returns rows from one or more tables specified by the join-expr clause.

The columns returned in the result-set are specified using either an asterisk (returning all columns), or a column separated list of select-element.

The optional TOP clause restricts the result-set to the specified number of rows. The PERCENT option, limits the rows returned to a percentage of the total number of rows. Without the PERCENT option, TOP returns a result-set containing no more than the specified number of rows.

The optional WITH TEMPLATES clause includes template objects in the result set.

The keywords ALL and DISTINCT control whether duplicate rows are returned in the result-set. The ALL option allows duplicated rows. The DISTINCT option removes duplicated rows. If neither ALL nor DISTINCT are specified, ALL is assumed.

The optional WHERE clause filters the result set to only include rows for which the associated condition is true.

The optional GROUP BY clause is intended to be used in conjunction with aggregate functions (see expr-primary-sumfunc ). The GROUP BY clauses specifies a list of columns to create result set groups. All other columns not specified by the GROUP BY clause must be included via an expression including an aggregate function.

The optional HAVING clause further filters the result set to only include groups for which the associated condition is true.

Examples:

Example 1:Return the 10 most recently updated points:

SELECT TOP( 10 ) Id,FullName,CurrentTime

FROM CDBPOINT

ORDER BY CurrentTime


Example 2:Return a list of database groups with points together with the number of points in each group:

SELECT ParentGroupName,Count(*)

FROM CDBPOINT

GROUP BY ParentGroupName

Example 3:Return a list of database groups with more than 5 points in a group, together with the number of points in each group:

SELECT ParentGroupName,Count(*)

FROM CDBPOINT

GROUP BY ParentGroupName

HAVING Count(*) > 5


Disclaimer

Geo SCADA Expert 2020