in Education by
SELECT id, amount FROM report I need amount to be amount if report.type='P' and -amount if report.type='N'. How do I add this to the above query? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
SELECT Id, IF(type = 'P1', amount, amount * -1) as amount FROM report If the condition is null, in the case of a null amount you can use this to handle it: SELECT Id, IF(type = 'P1', IFNULL(amount,0), IFNULL(amount,0) * -1) as amount FROM report Are you interested in learning SQL from scratch! Have a look at this interesting video on SQL provided by Intellipaat: In the Above code, IFNULL(amount,0) this means it will return amount if the amount is assigned not null but if the amount is assigned as null then it’ll result in ‘zero’.

Related questions

0 votes
    I am trying to INSERT INTO a table using the input from another table. Although this is entirely feasible ... the underlying database? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I have a .sql file with an export from phpMyAdmin. I want to import it into a different server using the ... create a database first? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    How can I reset the AUTO_INCREMENT of a field? I want it to start counting from 1 again. Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I want to put my Results of a hiveql query into a CSV file. How can I do it? I tried doing this, but ... select goods from the table; Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    I Have a soccer database, and I have a trigger (notas) that is calculating a player rating after ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I would like to take a list of names (e.g. john, mary, paul) and create a SQLite "select" ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    How can a column with a default value be added to an existing table in SQL Server 2000 / SQL Server 2005? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    How to set same number 'priority' with one query for Mercedes. +--------------------- ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    The text data I have for a column in database in an enterprise application (uses hibernate) is huge and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    The text data I have for a column in database in an enterprise application (uses hibernate) is huge and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 19, 2022 in Education by JackTerrance
0 votes
    The text data I have for a column in database in an enterprise application (uses hibernate) is huge and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    I want to select rows from a DataFrame based on values in some column in pandas, How can I do it? I ... WHERE column_name = some_value Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    How do I perform an IF...THEN in an SQL SELECT statement? For example: SELECT IF(Obsolete = 'N' OR ... Saleable, * FROM Product Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
...