sql - Display employee name,total salary of each employee(total salary=salary+commission) -


display employee name, total salary of each employee.

conditions:

  • if commission not null total salary=(salary + commission)
  • else total salary = salary;

here table:

table name: myemp

columns:

empno [primary key], name, salary, commission, deptno  create table myemp (       empno number primary key,      name varchar2(20),      salary number,      commission number,      deptno number ); 

query:

select     name, salary, commission,     (salary + ((salary*commission) / 100)) "total_salary"  myemp; 

this query give incorrect result.

when commission null, total_salary = 0. should total_salay=salary;

how fix this?

my table below: sql> select * emp;

 empno ename      job              mgr hiredate         sal       comm     deptno 

  7369 smith      clerk           7902 17-dec-80        800                    20   7499 allen      salesman        7698 20-feb-81       1600        300         30   7521 ward       salesman        7698 22-feb-81       1250        500         30   7566 jones      manager         7839 02-apr-81       2975                    20   7654 martin     salesman        7698 28-sep-81       1250       1400         30   7698 blake      manager         7839 01-may-81       2850                    30   7782 clark      manager         7839 09-jun-81       2450                    10   7788 scott      analyst         7566 19-apr-87       3000                    20   7839 king       president            17-nov-81       5000                    10   7844 turner     salesman        7698 08-sep-81       1500          0         30   7876 adams      clerk           7788 23-may-87       1100                    20   7900 james      clerk           7698 03-dec-81        950                    30   7902 ford       analyst         7566 03-dec-81       3000                    20   7934 miller     clerk           7782 23-jan-82       1300                    10 

14 rows selected.

my result table while have null value in comm column is:

sql> select empno,ename,sal,comm,(sal+nvl(comm,0)) "total_sal" emp;

 empno ename             sal       comm  total_sal 

  7369 smith             800                   800   7499 allen            1600        300       1900   7521 ward             1250        500       1750   7566 jones            2975                  2975   7654 martin           1250       1400       2650   7698 blake            2850                  2850   7782 clark            2450                  2450   7788 scott            3000                  3000   7839 king             5000                  5000   7844 turner           1500          0       1500   7876 adams            1100                  1100   7900 james             950                   950   7902 ford             3000                  3000   7934 miller           1300                  1300 

14 rows selected.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -