Difference between revisions of "AVA SQL"
| Line 149: | Line 149: | ||
0.293 seconds elapsed. | 0.293 seconds elapsed. | ||
| − | + | ===Time Series Functions=== | |
| − | + | ||
| − | + | ||
| − | + | ====CUMSUM==== | |
| − | + | Cumulative sum. Sums over a pre-ordered data column. | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ava> update cs: cumsum(open) from a group by sec_id | |
| − | + | 0.339 seconds elapsed. | |
| + | ava> select date, sec_id, cs from a where sec_id = "ss600001" | ||
| + | TABLE NAME: a | NUMBER OF RECORDS: 1,709 | ||
| + | --------------------------------------------------- | ||
| + | date | sec_id | cs | | ||
| + | ---------- | ---------- | ---------- | | ||
| + | 2003/01/01 | ss600001 | 4.99 | | ||
| + | 2003/01/02 | ss600001 | 9.96 | | ||
| + | 2003/01/03 | ss600001 | 14.91 | | ||
| + | 2003/01/06 | ss600001 | 19.91 | | ||
| + | 2003/01/07 | ss600001 | 24.94 | | ||
| + | 0.076 seconds elapsed. | ||
| − | + | To sort the table to a particular order: | |
| − | + | ava> .sort a order by date desc | |
| − | + | 0.052 seconds elapsed. | |
| + | ava> select * from a | ||
| + | TABLE NAME: a | NUMBER OF RECORDS: 3,252,871 | ||
| + | --------------------------------------------------- | ||
| + | date | sec_id | open | high | low | close | volume | adj_close | | ||
| + | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | | ||
| + | 2011/04/04 | ss900946 | 0.47 | 0.47 | 0.47 | 0.47 | 0 | 0.47 | | ||
| + | 2011/04/04 | ss900940 | 0.23 | 0.23 | 0.23 | 0.23 | 0 | 0.23 | | ||
| + | 2011/04/04 | sz000863 | 3.50 | 3.50 | 3.50 | 3.50 | 0 | 3.50 | | ||
| + | 0 seconds elapsed. | ||
| + | |||
| + | ====CUMPROD==== | ||
| + | Cumulative product. Product over a pre-ordered data column. | ||
| + | ava> update cp: cumprod(open) from a group by sec_id | ||
| + | 0.588 seconds elapsed. | ||
| + | ====RANK==== | ||
| + | |||
| + | ava> update rk: rank(volume) from a group by sec_id | ||
| + | 0.701 seconds elapsed. | ||
| + | ava> select date, sec_id, volume, rk from a | ||
| + | TABLE NAME: a | NUMBER OF RECORDS: 3,252,871 | ||
| + | --------------------------------------------------- | ||
| + | date | sec_id | volume | rk | | ||
| + | ---------- | ---------- | ---------- | ---------- | | ||
| + | 2000/10/16 | ss600008 | 797800 | 590 | | ||
| + | 2000/10/16 | ss600018 | 346400 | 265 | | ||
| + | 2000/10/16 | ss600130 | 438300 | 864 | | ||
| + | 0 seconds elapsed. | ||
| + | |||
| + | |||
| + | ====WRANK==== | ||
| + | '''SYNTAX:''' wrank(COLUMN_NAME,BINS) | ||
| + | Rank a column and assign the ranks to bins. | ||
| + | ava> update rk: wrank(volume,10) from a group by sec_id | ||
| + | 0.714 seconds elapsed. | ||
| + | ava> select date, sec_id, volume, rk from a | ||
| + | TABLE NAME: a | NUMBER OF RECORDS: 3,252,871 | ||
| + | --------------------------------------------------- | ||
| + | date | sec_id | volume | rk | | ||
| + | ---------- | ---------- | ---------- | ---------- | | ||
| + | 2000/10/16 | ss600008 | 797800 | 3 | | ||
| + | 2000/10/16 | ss600018 | 346400 | 2 | | ||
| + | 2000/10/16 | ss600130 | 438300 | 4 | | ||
| + | 0 seconds elapsed. | ||
| + | |||
| + | ===Window Functions=== | ||
| + | |||
| + | ====FIRST==== | ||
| + | ====LAST==== | ||
| + | ====LAG==== | ||
| + | ====LEAD==== | ||
| + | ====MAVG==== | ||
| + | ====MSUM==== | ||
| + | ====MSTD==== | ||
| + | ====EMA==== | ||
| + | Exponential moving average | ||
| + | |||
| + | ===Row-wise Aggregation Functions=== | ||
| + | ====WSUM==== | ||
| + | ====WAVG==== | ||
| + | ====WSTD==== | ||
| + | ====WMIN==== | ||
| + | ====WMAX==== | ||
| + | ====WCOUNT==== | ||
==Table Join Functions== | ==Table Join Functions== | ||
==Data Conversion Functions== | ==Data Conversion Functions== | ||
| + | ===to_date=== | ||
| + | ===to_string=== | ||
| + | ===to_time=== | ||
| + | ===to_long=== | ||
| + | ===to_float=== | ||
| + | ===to_integer=== | ||
| + | ===to_unsigned_integer=== | ||
Revision as of 20:48, 14 May 2013
AVA Database follows SQL '92 standard. In addition, AVA's unique SQL adds new features that facilitate high speed analytics and data mining.
Contents |
Some AVA SQL conventions
Keyword cases
Keywords are case-insensitive. Both the low case or upper case, or mixed case will point to the same keyword. However, the column names and table names are case-sensitive.
Column assignment
A column can be created from an SQL update. There are two ways to assign a resulting column to a named column:
SQL convention
The "AS" clause to assign the results to a column.
ava> update low * 123.1 as new_low from a 0.024 seconds elapsed.
Non-SQL convention
A shortcut to create a column is by the syntax: "COLUMN_NAME: ...":
ava> update new_low: low * 123.1 from a 0.029 seconds elapsed.
Both will generate the same result:
ava> select * from a
TABLE NAME: a | NUMBER OF RECORDS: 3,252,871
---------------------------------------------------
date | sec_id | open | high | low | close | volume | adj_close | new_low |
---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- |
2000/10/16 | ss600008 | 20.40 | 20.58 | 20.18 | 20.58 | 797800 | 16.87 | 2,484.16 |
2000/10/16 | ss600018 | 20.16 | 20.50 | 20.15 | 20.20 | 346400 | 17.60 | 2,480.46 |
2000/10/16 | ss600130 | 28.08 | 28.29 | 27.16 | 27.23 | 438300 | 24.89 | 3,343.40 |
0.001 seconds elapsed.
Analytics Functions
Mathematical Functions
Modulus ( % )
Take the modulus of the two numbers:
ava> select date, sec_id, ol: open % low from a
TABLE NAME: a | NUMBER OF RECORDS: 3,252,871
---------------------------------------------------
date | sec_id | ol |
---------- | ---------- | ---------- |
2000/10/16 | ss600008 | 0.00 |
2000/10/16 | ss600018 | 0.00 |
2000/10/16 | ss600130 | 1.00 |
0.036 seconds elapsed.
Power ( ^ )
Take the power of ( a real number ):
ava> select date, sec_id, o: open ^ 2 from a
TABLE NAME: a | NUMBER OF RECORDS: 3,252,871
---------------------------------------------------
date | sec_id | o |
---------- | ---------- | ---------- |
2000/10/16 | ss600008 | 416.16 |
2000/10/16 | ss600018 | 406.43 |
2000/10/16 | ss600130 | 788.49 |
0.081 seconds elapsed.
Factorial ( factorial )
Take factorial of an integer:
ava> select date, sec_id, f: factorial(5) * open from a
TABLE NAME: a | NUMBER OF RECORDS: 3,252,871
---------------------------------------------------
date | sec_id | f |
---------- | ---------- | ---------- |
2000/10/16 | ss600008 | 2,448.00 |
2000/10/16 | ss600018 | 2,419.20 |
2000/10/16 | ss600130 | 3,369.60 |
0.02 seconds elapsed.
Other mathematical functions
- ABS(): Absolute Value
- EXP(): Exponential, e ( 2.72 ) to a power ( real number )
- SIGN(): Sign of a number
- LOG(): Log of e (2.72)
- LOG10(): LOG of 10
- SIN(): SIN
- COS(): COS
- TAN(): Tangent
- ASIN(): Arc Sin
- ACOS(): Arc Cos
- ATAN(): Arc Tangent
Statistical Functions
SUM
Aggregate function. Sum over a group ( option )
ava> select s: sum(volume) from a group by sec_id
TABLE NAME: a | NUMBER OF RECORDS: 1,718
---------------------------------------------------
sec_id | s |
---------- | ---------- |
ss000001 | 407718300 |
ss600000 | 424768664 |
ss600001 | 481888440 |
0.29 seconds elapsed.
AVG
Aggregate function. Average over a group ( option )
ava> select s: avg(close) from a group by sec_id
TABLE NAME: a | NUMBER OF RECORDS: 1,718
---------------------------------------------------
sec_id | s |
---------- | ---------- |
ss000001 | 2,214.42 |
ss600000 | 17.70 |
ss600001 | 5.31 |
0.288 seconds elapsed.
STD
Aggregate function. Standard Deviation over a group ( option )
ava> select s: std(close) from a group by sec_id
TABLE NAME: a | NUMBER OF RECORDS: 1,718
---------------------------------------------------
sec_id | s |
---------- | ---------- |
ss000001 | 1,034.01 |
ss600000 | 11.83 |
ss600001 | 1.53 |
0.291 seconds elapsed.
MIN
Aggregate function. Minimum value over a group ( option )
ava> select s: min(close) from a group by sec_id
TABLE NAME: a | NUMBER OF RECORDS: 1,718
---------------------------------------------------
sec_id | s |
---------- | ---------- |
ss000001 | 1,011.50 |
ss600000 | 6.48 |
ss600001 | 2.72 |
0.292 seconds elapsed.
MAX
Aggregate function. Maximum value over a group ( option )
ava> select s: max(close) from a group by sec_id
TABLE NAME: a | NUMBER OF RECORDS: 1,718
---------------------------------------------------
sec_id | s |
---------- | ---------- |
ss000001 | 6,092.06 |
ss600000 | 61.59 |
ss600001 | 10.92 |
0.293 seconds elapsed.
Time Series Functions
CUMSUM
Cumulative sum. Sums over a pre-ordered data column.
ava> update cs: cumsum(open) from a group by sec_id
0.339 seconds elapsed.
ava> select date, sec_id, cs from a where sec_id = "ss600001"
TABLE NAME: a | NUMBER OF RECORDS: 1,709
---------------------------------------------------
date | sec_id | cs |
---------- | ---------- | ---------- |
2003/01/01 | ss600001 | 4.99 |
2003/01/02 | ss600001 | 9.96 |
2003/01/03 | ss600001 | 14.91 |
2003/01/06 | ss600001 | 19.91 |
2003/01/07 | ss600001 | 24.94 |
0.076 seconds elapsed.
To sort the table to a particular order:
ava> .sort a order by date desc
0.052 seconds elapsed.
ava> select * from a
TABLE NAME: a | NUMBER OF RECORDS: 3,252,871
---------------------------------------------------
date | sec_id | open | high | low | close | volume | adj_close |
---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- |
2011/04/04 | ss900946 | 0.47 | 0.47 | 0.47 | 0.47 | 0 | 0.47 |
2011/04/04 | ss900940 | 0.23 | 0.23 | 0.23 | 0.23 | 0 | 0.23 |
2011/04/04 | sz000863 | 3.50 | 3.50 | 3.50 | 3.50 | 0 | 3.50 |
0 seconds elapsed.
CUMPROD
Cumulative product. Product over a pre-ordered data column.
ava> update cp: cumprod(open) from a group by sec_id 0.588 seconds elapsed.
RANK
ava> update rk: rank(volume) from a group by sec_id
0.701 seconds elapsed.
ava> select date, sec_id, volume, rk from a
TABLE NAME: a | NUMBER OF RECORDS: 3,252,871
---------------------------------------------------
date | sec_id | volume | rk |
---------- | ---------- | ---------- | ---------- |
2000/10/16 | ss600008 | 797800 | 590 |
2000/10/16 | ss600018 | 346400 | 265 |
2000/10/16 | ss600130 | 438300 | 864 |
0 seconds elapsed.
WRANK
SYNTAX: wrank(COLUMN_NAME,BINS) Rank a column and assign the ranks to bins.
ava> update rk: wrank(volume,10) from a group by sec_id
0.714 seconds elapsed.
ava> select date, sec_id, volume, rk from a
TABLE NAME: a | NUMBER OF RECORDS: 3,252,871
---------------------------------------------------
date | sec_id | volume | rk |
---------- | ---------- | ---------- | ---------- |
2000/10/16 | ss600008 | 797800 | 3 |
2000/10/16 | ss600018 | 346400 | 2 |
2000/10/16 | ss600130 | 438300 | 4 |
0 seconds elapsed.
Window Functions
FIRST
LAST
LAG
LEAD
MAVG
MSUM
MSTD
EMA
Exponential moving average