I collected from my friends, for DB2 interviews these SQL queries you need to practice more times.
SQL Queries for Interviews
1) What are the different SELECT statements?
A). select clause: Enumerates the column names and related constructs
from clause: Describes the target(s) from which the data will be gathered and how multiple targets should be joined
where clause: Describes conditions known as predicates that the target data must meet in order to be included or considered for the query results
group by clause: Describes how nonaggregated data will be handled in the presence of related aggregated data (sums, averages, and so on)
having clause: Optional equivalent to the where clause, which is used as criteria to judge groups formed in the group by clause
order by clause: Provides optional ordering to the otherwise unordered sets of data and results
2) What are the frequently referred DB2 System tables?
SYSTABLES.SYSIBM
Information about all tables in the database
SYSINDEXES.SYSIBM
Information about the indexes on all tables
SYSVIEWS.SYSIBM
Information on all views in the database
3) Sample SQL query fro SYSTABLES?
A.
select name, creator
from sysibm.systables
where creator = 'FUZZY'
Result:
NAME CREATOR
-------------------
ACT FUZZY
ADEFUSR FUZZY
CATALOG FUZZY
4) How Group By works in SELECT statement?
A. Group By works on non-aggregate columns.
select workdept, sum(salary) as newsalary
from employee
group by workdept
5) How having works in SELECT statement?
A. You can use the having clause to apply criteria to aggregated groups. Think of the having clause as similar to the where clause, but applying only to the aggregate groups after they are formed by the group by clause.
select workdept, sum(salary) DeptSal
from employee
group by workdept
having sum(salary) > 100000
Result
WORKDEPT DEPTSAL
-------------------------------
D11 646620.00
A00 354250.00
E11 317140.00
C01 308890.00
D21 358680.00
E21 282520.00
These five questions asked in many interviews. Keep reading my blog for more beautiful posts!