Sybase Clauses

Sybase Clauses: Clauses are used to grouping and sorting the data. Sybase clauses are group by, order by, having and compute.

Group By Clause:

  • Group by clause divides the output of the given query into groups.
  • We can group by one or more column names.
  • When group by is used with aggregate functions, group by clause retrieves the calculations in each subgroup and returns multiple rows.
  • We can use maximum 16 columns or expressions in a group by clause.
  • We can use where clause and group by clause in query.


select column1, column2, …. columnn
from table
group by column1


select account_type, account_id
from accounts
group by account_id

select pub_id, type, sum(total_sales)
from titles
group by pub_id, type

Having Clause:

  • Having clause is used to display or filter the rows defined by the group clause.
  • Having clause is used to set condition for group by clause.


select column1, cloumn2 from table_name
group by column1
having condition


select deptno from emp
group by deptno
having count(*)>1

Order by clause:

  • Order by clause is used to sort the output.
  • Sort is either in ascending or descending order.


select column1, column2 from table_name
order by column1 [asc/desc]


select account_id, account_name, account_type from accounts
orderby account_id asc

Compute Clause: Compute clause is used with row aggregates to produce reports for subtotals and summaries.


compute row_aggregate(column_name1)
[, row_aggregate(column_nam1e)]…
[by column_name1 [, column_name1]…]

Powered by k2schools