Sql raise error

147 views Asked by At

table contains a record of name salary

like this I want a deduction of 5000 from every employee. If the salary < 0 then i need to display "insuffiecient for deduction" if salary > 0 then " can be deducted"

This is the images of the table.

enter image description here

2

There are 2 answers

0
Chiragkumar Thakar On

Try this solution, i have added case when, which will help you.

Note: you can add the field as per your requirement

SELECT Emno, EmName, 
       CASE WHEN sal < 0 THEN "insuffiecient for deduction" 
            ELSE "can be deducted" END As Status 
FROM tablename
1
Gene On

Try the query below:

SELECT `name`, `sal`,  IF((`sal`-5000)<0,'insufficient for deduction','can be deducted') AS `status` FROM `employee`;

I only use the name and sal field since this two fields are only needed to solve your problem. The formula used was:

(`sal`-5000)<0

which means that the salary of certain employee will be deducted by 5000 and then immediately compare if it's negative or positive. If the result is negative it means that it's 'insufficient for deduction' else 'can be deducted'.