Tuesday, July 6, 2010

queries1

Display the orders having a total amount of order less than 2000

Ans: select orderid,sum(unitprice*quantity) from orderdetails group by orderid
having sum(unitprice*quantity) >2000


Display the firstname and lastname as a single name in a column(Name it as "Name")along with the orderid in which he belongs
(leave a space b/w the names)

Ans: select e.firstname||' '||e.lastname as Name, o.orderid from employees e join orders o on e.employeeid=o.employeeid

Display the current age of employees along with first and last name

Ans: select trunc(months_between(sysdate,birthdate)/12) "AGE" from employees