Reportizer Documentation
Contents Index

SQL Query Examples

Top Previous Next

Here only the basic examples of database queries are shown. This information is mainly for novices. If you need more complex queries, please refer to SQL tutorials and your database documentation.

1. Select records from the table payments where value of the field paysum is greater than 400 and less than 2000:

SELECT *
FROM payments
WHERE paysum > 400 AND paysum < 2000

2. Select records from the fields number and sum of the table payments where values of the field paysum are greater than 400 and less than 2000 and sort this data by the field paysum (in descending order):

SELECT payments.number, payments.paysum
FROM payments
WHERE paysum > 400 AND paysum < 2000
ORDER BY paysum DESC

3. Select information about number and amount of large orders (i.e. orders where amount is greater than 5000) from the table orders grouped by order_date column:

select o.order_date, count(o.order_id) as order_count, sum(o.order_amount) as total_order_amount
from orders o
where order_amount > 5000
group by o.order_date
order by o.order_date

4. Select data from all fields of the table PAYMENT, and the payment date and payment sum ranges must be specified as parameters to let the user ability to input them before report is previewed:

SELECT *
FROM PAYMENT
WHERE PAYMENTDATE > :Param1 /*ParamType=Date*/ AND PAYMENTSUM > :Param2 /*ParamType=Float*/

(such comments are added to let the application automatically select parameter types, without needing to do this by the user; but you can use Parameters section on the Data Source page instead).