Once database is created, the user can query the information with SELECT statement.
The basic syntax for the SELECT statement is:
SELECT attribute1, attribute2, ... FROM table_name
SELECT with LAST, SINCE, or BETWEEN Clause:
The user can use LAST clause to query the last numbers of rows in a table by using the following syntax:
SELECT attribute1, attribute2, ... FROM table_name LAST number
For time-bounded sliding table, the user can query the last number of rows within a specified time window as follows:
SELECT attribute1, attribute2, ... FROM sliding_table_name LAST time_window
In addition, the user can query rows starting from a specified time in a time-bounded sliding table by SINCE clause. The syntax is:
SELECT attribute1, attribute2, ... FROM sliding_table_name SINCE date_time
Further, the user can also query data within a specified time frame by using the BETWEEN clause as follows:
SELECT attribute1, attribute2, ... FROM sliding_table_name BETWEEN start_date_time AND end_date_time
SELECT with FILTER BY SAMPLE Clause:
BigObject supports table sampling within FILTER BY clause. This is particularly useful to have a quick glance at a big table. The sampling syntax is as follows:
SELECT attribute1, attribute2, ... FROM table_name FILTER BY SAMPLE sample_number
The sample_number specifies the sampling ratio if it is a real number between 0.0 and 1.0. If it is an integer, it denotes the sample size of the table.
SELECT with WHERE Clause:
The user can specify the query with conditional filter using WHERE clause within SELECT statement.
The general syntax for this is following:
SELECT attribute1, attribute2, ... FROM table_name WHERE where_condition
The user can do query with string pattern match methods, such as LIKE or REGEXP (regular expression) in where clause as follows:
SELECT attribute FROM table_name WHERE attribute LIKE 'string_pattern'
SELECT attribute FROM table_name WHERE attribute REGEXP 'string_pattern'
SELECT with GROUP BY:
The user can take a step further in query by performing an analysis on a particular group of attribute(s).
The general syntax of such SELECT with GROUP BY statement is following:
SELECT attribute1, attribute2, ...., aggregate function() FROM table_name GROUP BY attribute1, attribute2, ...
See aggregate functions for the list of aggregate functions that BigObject supports.
SELECT with ORDER BY Clause:
The user can arrange the query result with an ORDER BY clause. The default ORDER BY clause will arrange data shown in ascending order. The user can use the word DESC in the ORDER BY clause if he would like to arrange the data in descending order.
Below is the general syntax of SELECT with ORDER BY clause:
SELECT atrribute1, atrribute2, ... FROM table_name ORDER BY attribute [ASC | DESC]
SELECT with LIMIT Clause:
Sometimes, the query result may be too long, the user can specify number of record shown with a LIMIT clause.
The general syntax for such clause are following:
SELECT attribute1, attribute2, ... FROM table_name LIMIT [offset], row_count
SELECT attribute1, attribute2,...FROM table_name LIMIT row_count OFFSET [offset]
If offset is omitted, the command will be executed from row 1.
The user can combine various select clauses in a select statement. The general syntax of a select statement is as follows:
SELECT attribute1, attribute2, ... FROM table_name [LAST clause] [FILTER BY clause] [WHERE clause] [GROUP BY clause] [ORDER BY clause] [LIMIT clause]
After the database is completed, the staff of ABC company is curious to know which gender has greater overall purchase power in term of revenue generated from the total sales. He may issue following command to do a quick search:
SELECT Customer.gender, SUM(total_price) FROM sales GROUP BY Customer.gender
A table will be shown as following:
If the ABC company staff wants to look for members whose age is over 60 to do some senior merchandise promotion, he can issue following command:
SELECT name, gender, age from Customer WHERE age > 60
He will get a long list of qualified people like this:
The staff may further organize above query result with an order by age.
SELECT name, gender, age from Customer WHERE age > 60 ORDER BY age
The return will be arrange as following:
On a separate occasion, the staff of ABC company is curious to know how many products carry the name beginning with "Fan" among all its current clients. The staff can issue either of the following two commands:
SELECT name FROM Product WHERE name LIKE 'Fan%'
SELECT name FROM Product WHERE name REGEXP '^Fan'
The staff will receive following result:
Finally, as we can recall, the original sales table that ABC company staff created looks like following:
If he just wants to take a glance of the rows 2-7, he may use one of the following SELECT command with LIMIT clause:
SELECT * from sales LIMIT 1, 6
SELECT * from sales LIMIT 6 OFFSET 1
The following list will be returned: