4
Answers

order by clause is not working in temp table?

Mohan Chandra

Mohan Chandra

8y
618
1
hi, i want to Find sum of two maximum salary from employee table in oracle.
my employee table as
 
EMP_ID           EMP_NAME                       CONTACTNO          SALARY
---------------      ---------------                           ----------                 ----------
Emp01              Mohan Chandra               9560498289          16500
Emp02              Dinesh                                9856895689          21000
Emp03              Sachin                                7858968956           18000
Emp04              Ajay                                    9136564555            9500
Emp05              Sneha                                 7585963212            10625
Emp06              Rahul                                  9163568958            11300
Emp07              Divya                                  7539895689             8500
Emp08              Nisha                                  9758695645           11485
 
 
now i am writing query as
create table temp  AS SELECT salary  from EMPLOYEE where rownum<3 order by salary desc;
select sum(salary) from TEMP;

but it is showing result 37500 instead of 39000.
when i written query to see temp table so it shows
 SALARY ----------      21000       16500 

instead of
 SALARY ----------      21000       18000 

so what should i do for this.
i want to find sum of two maximum salary from employee table.

my another question is i want to select empname,salary, bonus.and bonus column will be three months of salary per employees.so what should i do?please give me solution.

    EMP_NAME      Salary     Bonus -------------- --------------------
Answers (4)