TARGET LIST
Select 문이 대상으로 하는 컬럼 또는 Subquery 의 리스트이다.
Target list에 사용된 Subquery는 WHERE 조건절에서 사용되는 Subquery와 같이 두 개 이상의 값을 갖거나 두 개 이상의 결과 컬럼을 갖는 경우에는 오류로 처리된다.
This is a list of columns or subqueries targeted by the Select statement .
The subquery used in the target list is treated as an error if it has two or more values or two or more result columns, such as a subquery used in the WHERE clause.
Code Block | ||||
---|---|---|---|---|
| ||||
SELECT i1, i2 ... SELECT i1 (Select avg(c1) FROM t1), i2 ... |
CASE
구문statement
Code Block | ||||
---|---|---|---|---|
| ||||
CASE <simple_case_expression|searched_case_expression> [else_clause] END simple_case_expression ::= expr WHEN comparison_expr THEN return_expr [WHEN comparison_expr THEN return_expr ...] searched_case_expression ::= WHEN condtion_expr THEN return EXPR [WHEN condtion_expr THEN return EXPR ...] else_clause ::= ELSE else_value_expr |
일반적인 프로그램 언어의 This is an expression that supports the IF ... THEN ... ELSE블록을 지원하는 표현식이다. ELSE block of a typical programming language. simple_case_expression은 하나의 컬럼이나 표현식이 when 뒤에 오는 comparison_expr 값과 같은 경우 return_expr을 반환하는 형태로 수행되며 이 when ... then 절은 원하는 만큼 반복하여 기술할 수 있다_expression is executed in the form of return_expr when one column or expression is equal to the value of comparison_expr followed by when, and this when ... then clause can be repeated as many times as desired.
searched_case_expression은 CASE 이후에 표현식을 지정하지 않고 when절에 비교연산자를 포함한 조건절을 기술한다. 각 비교연산의 결과가 참이면 then 절의 값을 반환한다. else 절은 when 절들의 값이 만족하지 않을 경우(expression 결과가 NULL인 경우에도) else_value를 반환한다expression does not specify an expression after CASE but describes a conditional clause that includes a comparison operator in the when clause. If the result of each comparison operation is true, then the value of the then clause is returned. The else clause returns else_value if the value of the when clause is not satisfied (even if the expression is NULL).
Code Block | ||||
---|---|---|---|---|
| ||||
select * from t1; I1 I2 --------------------------- 2 2 1 1 [2] row(s) selected. select case i1 when 1 then 100 end from t1; case i1 when 1 then 100 end ------------------------------ NULL 100 [2] row(s) selected. |
In the simple_case_expression의 예제에서 i1 컬럼의 값이 2인 경우에 해당하는 값이 없으면 NULL을 반환한다expression example, if the value of the i1 column is 2, NULL is returned.
Code Block | ||||
---|---|---|---|---|
| ||||
select case when i1 > 0 then 100 when i1 > 1 then 200 end from t1; case when i1 > 0 then 100 when i1 > 1 then 200 end ------------------------------------------ 100 100 [2] row(s) selected. |
Since searched_case_expression에서 만족하는 첫 번째 조건절을 반환하므로 첫 번째 조건절의 반환값인 100이 반환되며 두 번째 조건절은 실행이 되지 않는다expression returns the first condition that satisfies the condition, 100 is returned, and the second condition is not executed.
FROM
FROM 절에는 테이블 이름이나 Inline view를 지정할 수 있다. 테이블 간의 Join을 수행하려면 테이블 혹은 Inline view를 쉼표(,)로 구분해서 나열한다You can specify a table name or an Inline view in the FROM clause. To perform a join between tables, lists the table or Inline view separated by a comma (,).
Code Block | ||||
---|---|---|---|---|
| ||||
FROM table_name |
Retrieves data in the table specified by table_name로 지정한 테이블 내의 데이터를 검색한다name.
SUBQUERY(INLINE VIEW)
사용Code Block | ||||
---|---|---|---|---|
| ||||
FROM (Select statement) |
괄호로 둘려쳐진 subquery의 내용에 대하여 데이터를 검색한다Retrievse data for the contents of the subquery enclosed in parentheses.
Info |
---|
마크베이스 서버는 correlated subquery를 지원하지 않으므로 outer query에서 subquery 내의 column을 참조할 수 없다Machbase server does not support correlated subqueries, so you can not reference columns in a subquery in an outer query. |
JOIN(INNER JOIN)
Code Block |
---|
FROM TABLE_1, TABLE_2 |
두 개의 테이블 Joins two tables, table_1 과 and table_2를 JOIN한다2. INNER JOIN은 테이블이 3개 이상 나열될 때에도 사용이 가능하며 WHERE 절에 검색 조건절과 JOIN 조건절을 모두 기술하여 사용한다 An INNER JOIN can be used when three or more tables are listed, and both the search condition and the conditional clause are described in the WHERE clause.
Code Block |
---|
SELECT t1.i1, t2.i1 FROM t1, t2 WHERE t1.i1 = t2.i1 AND t1.i1 > 1 AND t2.i2 = 3; |
INNER JOIN
및and OUTER JOIN
Supports ANSI 스타일의 style INNER JOIN, LEFT OUTER JOIN, and RIGHT OUTER JOIN을 지원한다JOIN. FULL OUTER JOIN은 지원하지 않는다JOIN is not supported.
Code Block |
---|
FROM TABLE_1 [INNER|LEFT OUTER|RIGHT OUTER] JOIN TABLE_2 ON expression |
ANSI 스타일 JOIN절의 ON절에는 JOIN에서 수행하는 조건절을 사용한다. OUTER JOIN 질의에서 where절에 Inner table(ON 절의 조건을 만족하지 않으면 NULL이 채워지는 테이블)에 대한 조건절이 있는 경우, 해당 질의는 INNER JOIN으로 변환된다The ON clause of the ANSI-style JOIN clause uses the conditional clause that is performed by the JOIN. If the WHERE clause in the OUTER JOIN query has a clause for an inner table (a table that is filled with NULL if the condition of the ON clause is not satisfied), the query is converted to an INNER JOIN.
Code Block |
---|
SELECT t1.i1 t2.i1 FROM t1 LEFT OUTER JOIN t2 ON (t1.i1 = t2.i1) WHERE t2.i2 = 1; |
위 질의는 WHERE 절의 조건 The above query is converted to an INNER JOIN by the condition t2.i2 = 1에 의하여 INNER JOIN으로 변환된다1 in the WHERE clause.
PIVOT
Info |
---|
PIVOT 구문은 마크베이스 5.The PIVOT syntax is supported from Machbase version 5.6 버전부터 지원한다. |
pivot_clause:
PIVOT 구문은 ROW로 출력되는 GROUP BY에 대한 집계 결과를 컬럼으로 재배열하여 보여준다.
Inline view와 함께 사용되며 다음과 같이 수행된다.
- Inline view의 결과 컬럼 중 PIVOT 절에 사용되지 않은 컬럼으로 GROUP BY를 수행한 후 PIVOT IN 절에 나열된 값 별로 집계함수를 수행한다.
- 결과로 나온 grouping 컬럼과 집계 결과를 회전하여 컬럼으로 보여준다.
예) 여러 센서로부터 수집된 데이터에서 각 device 별로 value 값을 집계해서 출력하라.
CASE 구문을 통해 수행해야하는 질의를 PIVOT 구문을 통해 간단히 표현할 수 있다The PIVOT statement shows the aggregated results of GROUP BY output as ROW, rearranged into columns.
It is used in conjunction with the Inline view and is performed as follows.
- Performs GROUP BY on columns that are not used in the PIVOT clause of the inline view, and then performs aggregate functions on the values listed in the PIVOT IN clause.
- The resulting grouping column and the aggregation result are rotated and displayed as columns.
For example, aggregate the value of each device from the data collected from various sensors.
The query that should be performed through the CASE statement can be expressed simply through the PIVOT statement.
Code Block |
---|
-- w/o PIVOT SELECT * FROM ( SELECT regtime, SUM(CASE WHEN tagid = 'FRONT_AXIS_TORQUE' THEN dvalue ELSE 0 END) AS front_axis_torque, SUM(CASE WHEN tagid = 'REAR_AXIS_TORQUE' THEN dvalue ELSE 0 END) AS rear_axis_torque, SUM(CASE WHEN tagid = 'HOIST_AXIS_TORQUE' THEN dvalue ELSE 0 END) AS hoist_axis_torque, SUM(CASE WHEN tagid = 'SLIDE_AXIS_TORQUE' THEN dvalue ELSE 0 END) AS slide_axis_torque FROM result_d WHERE regtime BETWEEN TO_DATE('2018-12-07 00:00:00') AND TO_DATE('2018-12-08 05:00:00') GROUP BY regtime ) WHERE front_axis_torque >= 40 AND rear_axis_torque >= 20; -- w/ PIVOT SELECT * FROM ( SELECT regtime, tagid, dvalue FROM result_d WHERE regtime BETWEEN TO_DATE('2018-12-07 00:00:00') AND TO_DATE('2018-12-08 05:00:00') ) PIVOT (SUM(dvalue) FOR tagid IN ('FRONT_AXIS_TORQUE', 'REAR_AXIS_TORQUE', 'HOIST_AXIS_TORQUE', 'SLIDE_AXIS_TORQUE')) WHERE front_axis_torque >= 40 AND rear_axis_torque >= 20; -- Result regtime 'FRONT_AXIS_TORQUE' 'REAR_AXIS_TORQUE' 'HOIST_AXIS_TORQUE' 'SLIDE_AXIS_TORQUE' ------------------------------------------------------------------------------------------------------------------------------------------------------ 2018-12-07 16:42:29 840:000:000 12158 7244 NULL NULL 2018-12-07 14:56:26 220:000:000 3308 663 NULL NULL 2018-12-07 12:20:13 844:000:000 3804 113 NULL NULL 2018-12-07 11:10:01 957:000:000 8729 5384 NULL NULL 2018-12-07 17:46:57 812:000:000 7500 4559 NULL NULL 2018-12-07 14:30:06 138:000:000 5080 6817 NULL -429 2018-12-07 13:09:20 464:000:000 5233 1869 -7253 NULL 2018-12-07 15:43:03 539:000:000 7491 4453 NULL NULL ... |
WHERE
SUBQUERY의 사용
조건절에 대해서 subquery의 사용이 가능하다. IN 구문을 제외한 조건절에서 subquery가 두 개 이상의 레코드를 리턴하거나, subquery의 결과 컬럼이 두 개 이상인 경우는 지원하지 않는다Use of SUBQUERY
Subquery can be used for conditional statements. If the subquery returns more than one record in a clause except the IN clause, or if there is more than one result column in the subquery, it is not supported.
Code Block |
---|
WHERE i1 = (SELECT MAX(c2) FROM T1) |
subquery를 조건연산자 오른쪽에 괄호를 둘러쳐서 사용한다Uses subquery by surrounding parentheses to the right of the conditional operator.
Info |
---|
마크베이스 서버는 correlated subquery를 지원하지 않으므로 outer query에서 subquery 내의 column을 참조할 수 없다. |
Machbase server does not support correlated subqueries, so you can not reference columns in a subquery in an outer query. |
SEARCH Statement
The syntax is the same as for a regular database. However, a keyword index must be registered, and an additional search operation is possible by adding "SEARCH" as an operator keyword for text search.
Code Block |
---|
-- drop table realdual; create table realdual (id1 integer, id2 varchar(20), id3 varchar(20)); create keyword index idx1 on realdual (id2); create keyword index idx2 on realdual (id3); insert into realdual values(1, 'time time2', 'series series2'); select * from realdual; select * from realdual where id2 search 'time'; select * from realdual where id3 search 'series' ; select * from realdual where id2 search 'time' and id3 search 'series'; |
수행 결과는 다음과 같다The results are as follows.
Code Block |
---|
Mach> create table realdual (id1 integer, id2 varchar(20), id3 varchar(20)); Created successfully. Mach> create keyword index idx1 on realdual (id2); Created successfully. Mach> create keyword index idx2 on realdual (id3); Created successfully. Mach> insert into realdual values(1, 'time time2', 'series series2'); 1 row(s) inserted. Mach> select * from realdual; ID1 ID2 ID3 ------------------------------------------------------------ 1 time time2 series series2 [1] row(s) selected. Mach> select * from realdual where id2 search 'time'; ID1 ID2 ID3 ------------------------------------------------------------ 1 time time2 series series2 [1] row(s) selected. Mach> select * from realdual where id3 search 'series'; ID1 ID2 ID3 ------------------------------------------------------------ 1 time time2 series series2 [1] row(s) selected. Mach> select * from realdual where id2 search 'time' and id3 search 'series'; ID1 ID2 ID3 ------------------------------------------------------------ 1 time time2 series series2 [1] row(s) selected. |
ESEARCH
구문Statement
ESEARCH 구문은 ASCII 문자 텍스트에 대한 확장 검색을 가능하게 해주는 검색 키워드이다. 이러한 확장을 위해 % 문자를 이용하여 원하는 패턴의 검색을 수행한다. 이 Like 연산에서 앞에 %가 오는 경우 모든 레코드를 검사해야 하지만, ESEARCH의 장점은 이 경우에도 빠르게 해당 단어를 찾을 수 있다는 데 있다. 이 기능은 영문 문자열(에러 문자열 혹은 코드)의 일부를 찾을 때 매우 유용하게 사용할 수 있다.
The ESEARCH statement is a search keyword that enables extended searches on ASCII text. For this extension, search for the desired pattern is performed using the % character. In this Like operation, if all the records are checked before the %, the advantage of ESEARCH is that the words can be found quickly even in this case. This feature can be very useful when looking for a part of an English string (an error string or code).
Code Block | ||
---|---|---|
| ||
-- Example select id2 from realdual where id2 esearch 'bbb%'; id2 -------------------------------------------- bbb ccc1 aaa bbb1 [2] row(s) selected. 검색-- Search pattern 'bbb%'에 also 의하여includes bbb1도bbb1 검색in 결과에search 포함된다results. select id3 from realdual where id3 esearch '%cd%'; id3 -------------------------------------------- cdf def1 bcd/cdf1ad abc, bcd1 [3] row(s) selected. -- % 문자는 검색 pattern의 처음, 끝 뿐만 아니라 가운데에 있어도 동작한다character works in middle of search pattern as well as beginning and end. select id3 from realdual where id3 esearch '%cd%'; id3 -------------------------------------------- cdf def1 bcd/cdf1ad abc, bcd1 [3] row(s) selected. |
NOT SEARCH
구문NOT SEARCH는 SEARCH구문에서 검색되는 조건 이외의 레코드들에 대해서 참을 리턴하는 구문이다.
NOT ESEARCH는 사용할 수 없다Statement
NOT SEARCH is a statement that returns true for records other than those found in the SEARCH statement.
NOT ESEARCH can not be used.
Code Block |
---|
create table t1 (id integer, i2 varchar(10)); create keyword index t1_i2 on t1(i2); insert into t1 values (1, 'aaaa'); insert into t1 values (2, 'bbbb'); select id from t1 where i2 not search 'aaaa'; id -------------------------------------------- 2 [1] row(s) selected. |
REGEXP
구문Statement
REGEXP 구문은 정규표현식을 사용하여 데이터에 대한 검색을 수행하는데 사용된다. 일반적으로 특정 컬럼의 패턴을 정규표현식을 사용하여 데이터를 필터링하게 된다.
한가지 주의할 점은 REGEXP 구문을 사용할 경우 인덱스를 활용할 수 없기 때문에 전체 검색 범위를 줄이기 위해 반드시 다른 컬럼에 대한 인덱스 조건을 넣어서 전체적인 검색 비용을 낮춰야 한다.
특정 패턴을 검사하고자 할 때에는 SEARCH 혹은 ESEARCH를 통해 인덱스를 활용하도록 하고, 이를 통해 전체적인 데이터 건수가 작아진 상태에서 다시 REGEXP를 이용하는 것이 시스템 전체 효율 향상에 도움이 된다The REGEXP statement is used to perform searches on data using regular expressions. In general, patterns of a particular column are filtered using regular expressions.
One thing to keep in mind is that you can not use indexes when using the REGEXP clause, so you must lower the overall search cost by putting index conditions on other columns in order to reduce the overall search scope.
If you want to check a specific pattern, use index by SEARCH or ESEARCH, and then use REGEXP again in a state where the total number of data is small, it helps to improve the efficiency of the whole system.
Code Block |
---|
Mach> create table realdual (id1 integer, id2 varchar(20), id3 varchar(20)); create table dual (id integer); insert into dual values(1); insert into realdual values(1, 'time1', 'series1 series21'); insert into realdual values(1, 'time2', 'series2 series22'); insert into realdual values(1, 'time3', 'series3 series32'); Mach> select * from realdual where id2 REGEXP 'time' ; ID1 ID2 ID3 ------------------------------------------------------------ 1 time3 series3 series32 1 time2 series2 series22 1 time1 series1 series21 [3] row(s) selected. Mach> select * from realdual where id2 REGEXP 'time[12]' ; ID1 ID2 ID3 ------------------------------------------------------------ 1 time2 series2 series22 1 time1 series1 series21 [2] row(s) selected. Mach> select * from realdual where id2 REGEXP 'time[13]' ; ID1 ID2 ID3 ------------------------------------------------------------ 1 time3 series3 series32 1 time1 series1 series21 [2] row(s) selected. Mach> select * from realdual where id2 regexp 'time[13]' and id3 regexp 'series[12]'; ID1 ID2 ID3 ------------------------------------------------------------ 1 time1 series1 series21 [1] row(s) selected. Mach> select * from realdual where id2 NOT REGEXP 'time[12]'; ID1 ID2 ID3 ------------------------------------------------------------ 1 time3 series3 series32 [1] row(s) selected. Mach> SELECT 'abcde' REGEXP 'a[bcd]{1,10}e' from dual; 'abcde' REGEXP 'a[bcd]{1,10}e' --------------------------------- 1 [1] row(s) selected. |
IN
구문Statement
Code Block |
---|
column_name IN (value1, value2,...) |
IN 구문은 뒤의 value 리스트에서 만족할 경우 TRUE를 리턴한다. OR로 연결된 구문과 동일하다.
IN 구문과 SUBQUERY의 사용
조건절의 IN 구문의 오른쪽에 subquery를 사용할 수 있다. 단, IN 조건절의 왼쪽에는 컬럼 두 개 이상의 컬럼을 지정하면 오류로 처리하고 오른쪽의 subquery에서 리턴되는 결과 집합이 왼쪽 컬럼값에 존재하는지를 검사한다The IN statement returns TRUE if it is satisfied in the value list. It is the same as the syntax linked by OR.
Use In Statement and SUBQUERY
You can use a subquery to the right of the IN statement in the conditional statement. However, if you specify more than one column on the left side of the IN condition, it treats it as an error and checks whether the result set returned from the right subquery exists in the left column value.
Code Block |
---|
WHERE i1 IN (Select c1 from ...) |
Ui text box |
Info |
---|
마크베이스 서버는 correlated subquery를 지원하지 않으므로 outer query에서 subquery 내의 column을 참조할 수 없다. |
Machbase server does not support correlated subqueries, so you can not reference columns in a subquery in an outer query. |
BETWEEN Statement
Code Block |
---|
column_name BETWEEN value1 AND value2 |
BETWEEN 구문은 column의 값이 value1과 value2 범위에 있을 경우, TRUE를 리턴한다The BETWEEN statement returns TRUE if the value of column is in the range of value1 and value2.
RANGE
구문Statement
Code Block |
---|
column_name RANGE duration_spec; -- duration_spec : integer (YEAR | WEEK | HOUR | MINUTE | SECOND); |
지정된 컬럼에 대해 시간 조건절을 쉽게 지정하는 Range 연산자를 제공한다. Range 연산자는 (BEFORE 키워드로 지정하는 것처럼) 특정 시점을 지정하는 게 아니라 현재 시점부터의 시간 범위를 연산의 대상 조건으로 지정한다. 이 연산자를 사용하면 손쉽게 원하는 시간 범위 내의 결과 레코드들을 검색할 수 있다Provides a Range operator that allows you to easily specify a time condition for a given column. The Range operator specifies the time range from the current time as the target of the operation, rather than specifying a specific time (as specified by the BEFORE keyword). With this operator, you can easily retrieve result records within a desired time range.
Code Block |
---|
select * from test where id < 2 and c1 range 1 hour; ID C1 ----------------------------------------------- 1 2014-07-25 09:28:53 706:707:001 [1] row(s) selected. |
GROUP BY / HAVING
The GROUP BY 절은 SELECT 문으로 검색한 결과를 특정 컬럼을 기준으로 그룹화하기 위해 사용하며, 그룹별로 정렬을 수행하거나 집계 함수를 사용하여 그룹별 집계를 구할 때 사용한다. 그룹이란 GROUP BY 절에 명시된 컬럼에 대해 동일한 컬럼 값을 가지는 레코드들을 의미한다.GROUP BY 절 뒤에 HAVING 절을 결합하여 그룹 선택을 위한 조건식을 설정할 수 있다. 즉, GROUP BY 절로 구성되는 모든 그룹 중 HAVING 절에 명시된 조건식을 만족하는 그룹만 조회한다clause is used to group the results of a SELECT statement on a specific column. It is used when sorting by group or by aggregating functions by using aggregate functions. Group means records having the same column value for the column specified in the GROUP BY clause.You can combine the HAVING clause after the GROUP BY clause to set the conditional expression for group selection. That is, of all the groups constituted by the GROUP BY clause, only the group satisfying the conditional expression specified in the HAVING clause is inquired.
Code Block |
---|
SELECT ...
GROUP BY { col_name | expr } ,...[ HAVING <search_condition> ]
select id1, avg(id2) from exptab where id2 group by id1 order by id1;
id1 컬럼을 기준으로 id2의 평균값을 구한다. |
ORDER BY
ORDER BY 절은 질의 결과를 오름차순 또는 내림차순으로 정렬하며, ASC 또는 DESC와 같은 정렬 옵션을 명시하지 않으면 디폴트로 오름차순으로 정렬한다. ORDER BY 절을 지정하지 않으면, 조회되는 레코드의 순서는 질의에 따라 다르다
Obtain average value of id2 based on id1 column. |
ORDER BY
The ORDER BY clause sorts the query results in ascending or descending order. If no sorting options such as ASC or DESC are specified, the ORDER BY clause sorts by default in ascending order. If the ORDER BY clause is not specified, the order of the records to be queried depends on the query.
Code Block |
---|
SELECT ...
ORDER BY {col_name | expr} [ASC | DESC]
select id1, avg(id2) from exptab where id2 group by id1 order by id1;
id1 컬럼을 기준으로 id2의 평균값을 구한다. |
SERIES BY
SERIES BY 절은 정렬된 결과집합을 SERIES BY 조건절을 만족하는 연속된 결과값들로 추출한다. 만약 ORDER BY 절이 지정되지 않은 경우에는 _ARRIVAL_TIME 컬럼값을 이용하여 정렬된 결과를 생성하므로, _ARRIVAL_TIME 컬럼이 없는 휘발성 테이블이나 참조 테이블에 대한 질의나, GROUP BY 절을 이용하는 경우에는 반드시 ORDER BY 절을 이용해야 한다.
조건절을 만족하는 결과값들은 같은 SERIESNUM() 함수의 반환값을 갖게 된다.
Code Block |
---|
예를 들어 다음의 데이터에 대해서 Obtain average value of id2 based on id1 column. |
SERIES BY
The SERIES BY clause extracts the sorted result set as successive result values satisfying the SERIES BY condition. If the ORDER BY clause is not specified, it generates the sorted result using the _ARRIVAL_TIME column value. Therefore, if you use the GROUP BY clause or the query for a volatile table or lookup table that does not have the _ARRIVAL_TIME column, you must use the ORDER BY clause do.
The result values that satisfy the conditional clause will have the return value of the same SERIESNUM () function.
Code Block |
---|
For example, for the following data CREATE TABLE T1 (C1 INTEGER, C2 INTEGER); INSERT INTO T1 VALUES (0, 1); INSERT INTO T1 VALUES (1, 2); INSERT INTO T1 VALUES (2, 3); INSERT INTO T1 VALUES (3, 2); INSERT INTO T1 VALUES (4, 1); INSERT INTO T1 VALUES (5, 2); INSERT INTO T1 VALUES (6, 3); INSERT INTO T1 VALUES (7, 1); 아래의 질의는 다음의 결과를 출력한다.The following query produces the following output: SELECT C1,C2 FROM T1 ORDER BY C1 SERIES BY C2>1; C1 C2 --------------------------- 1 2 2 3 3 2 5 2 6 3 If you want to know the RANGE value of C1 where the value of the C2 column is 컬럼의larger 값이than 1, 보다you 큰can C1의 RANGE값을determine 알고the 싶은range 경우,by SERIESNUMoutputting 함수로to 각which 레코드가group 어느each 그룹에record 포함되는지를is 출력하여included RANGE를with 결정할the 수SERIESNUM 있다function. |
LIMIT
LIMIT 절은 출력되는 레코드의 개수를 제한할 때 사용한다. 결과 집합의 특정 행부터 마지막 행까지 출력하기 위해 정수를 지정할 수 있다The LIMIT clause is used to limit the number of records to be output. You can specify an integer to output from the first row to the last row of the result set
Code Block |
---|
LIMIT [offset,] row_count select id1, avg(id2) from exptab where id2 group by id1 order by id1 LIMIT 10; |
DURATION
DURATION
DURATION은 is a keyword that allows you to easily determine the data retrieval scope based on _arrival_time을 기준으로 데이터 검색 범위를 손쉽게 결정하도록 해 주는 키워드이다. BEFORE 구문과 함께 사용되어 특정 시점의 특정 데이터 범위를 설정하게 해 준다. 이 DURATION을 잘 활용하면 검색 성능을 현격하게 올림과 동시에 시스템 부하를 획기적으로 낮출 수 있다. 더 자세한 활용 용도는 다음을 참조한다time. Used with the BEFORE statement to set a specific range of data at a specific point in time. By using this DURATION, search performance can be dramatically increased and the system load can be dramatically reduced. For more detailed usage, please refer to the following.
Code Block |
---|
DURATION Number TimeSpec [BEFORE/AFTER Number TimeSpec] TimeSpec : YEAR | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND |
Code Block |
---|
create table t8(i1 integer); insert into t8 values(1); insert into t8 values(2); select i1 from t8; # Without BEFORE 절 없이clause select i1 from t8 duration 2 second; select i1 from t8 duration 1 minute; select i1 from t8 duration 1 hour; select i1 from t8 duration 1 day; select i1 from t8 duration 1 week; select i1 from t8 duration 1 month; select i1 from t8 duration 1 year; # DURATIONUsing 구문full 전체를DURATION 써서statement select i1 from t8 duration 1 second before 1 day; select i1 from t8 duration 1 minute before 1 day; select i1 from t8 duration 1 hour before 1 day; select i1 from t8 duration 1 day before 1 day; select i1 from t8 duration 1 week before 1 day; select i1 from t8 duration 1 month before 1 day; select i1 from t8 duration 1 year before 1 day; |
수행 결과는 다음과 같다The results are as follows.
Code Block |
---|
Mach> create table t8(i1 integer); Created successfully. Mach> insert into t8 values(1); 1 row(s) inserted. Mach> insert into t8 values(2); 1 row(s) inserted. Mach> select i1 from t8; i1 -------------- 2 1 [2] row(s) selected. # BEFORE 절 없이 Mach> select i1 from t8 duration 2 second; i1 -------------- 2 1 [2] row(s) selected. Mach> select i1 from t8 duration 1 minute; i1 -------------- 2 1 [2] row(s) selected. Mach> select i1 from t8 duration 1 hour; i1 -------------- 2 1 [2] row(s) selected. Mach> select i1 from t8 duration 1 day; i1 -------------- 2 1 [2] row(s) selected. Mach> select i1 from t8 duration 1 week; i1 -------------- 2 1 [2] row(s) selected. Mach> select i1 from t8 duration 1 month; i1 -------------- 2 1 [2] row(s) selected. Mach> select i1 from t8 duration 1 year; i1 -------------- 2 1 [2] row(s) selected. # DURATIONUsing 구문full 전체를DURATION 써서statement Mach> select i1 from t8 duration 1 second before 1 day; i1 -------------- [0] row(s) selected. Mach> select i1 from t8 duration 1 minute before 1 day; i1 -------------- [0] row(s) selected. Mach> select i1 from t8 duration 1 hour before 1 day; i1 -------------- [0] row(s) selected. Mach> select i1 from t8 duration 1 day before 1 day; i1 -------------- [0] row(s) selected. Mach> select i1 from t8 duration 1 week before 1 day; i1 -------------- [0] row(s) selected. Mach> select i1 from t8 duration 1 month before 1 day; i1 -------------- [0] row(s) selected. Mach> select i1 from t8 duration 1 year before 1 day; i1 -------------- [0] row(s) selected. |
SAVE DATA
질의의 결과를 CSV 데이터 파일로 바로 저장한다Saves the results of the query directly into the CSV data file.
Code Block | ||||
---|---|---|---|---|
| ||||
SAVE DATA INTO 'file_name.csv' [HEADER ON|OFF] [(FIELDS | COLUMNS) [TERMINATED BY 'char'] [ENCLOSED BY 'char']] [ENCODED BY coding_name] AS select query; |
옵션의 설명은 다음과 같다The options are described below.
옵션 | 설명 |
---|---|
HEADER (ON|OFF) | 생성할 csv 파일의 첫번째 라인에 컬럼명을 입력할지를 결정한다. 기본값은 OFF이다.Specifies the column delimiter and escape delimiter of the csv file to be created. |
(FIELDS|COLUMNS) TERMINATED BY 'term_char' ENCLOSED BY 'escape_char' | 생성할 csv 파일의 컬럼 구분자와 이스케이프 구분자를 지정한다Decides whether to enter the column name on the first line of the csv file to be created. The default is OFF. |
ENCODED BY coding_name coding_name = ( UTF8, MS949, KSC5601, EUCJP, SHIFTJIS, BIG5, GB231280 ) | 출력 데이터 파일의 인코딩 포맷을 지정한다. 기본값은 UTF8이다Specifies the encoding format of the output data file. The default value is UTF8. |
Code Block |
---|
SAVE DATA INTO '/tmp/aaa.csv' AS select * from t1; -- Execute select statement 문을and 실행하여write 그result 결과를to '/tmp/aaa.csv' file 파일에in csv 포멧으로 기록한다format. SAVE DATA INTO '/tmp/ccc.csv' HEADER ON FIELDS TERMINATED BY ';' ENCLOSED BY '\'' ENCODED BY MS949 AS select * from t1 where i1 > 100; -- Execute select 문을statement and 실행하여write 그result 결과를to /tmp/ccc.csv파일에csv 기록한다. 필드 구분자와 이스케이프 구분자를 각각 지정하고 저장되는 데이터의 인코딩은 MS949로 설정한다file. Specify field separator and escape separator, respectively, and set encoding of stored data to MS949. |