Skip to content
Advertisement

Tag: case

SQL Server => How to use “case when” on multiple column to show a formula result based on a condition in the same line

I’m trying to provide an overall result of a formula ([CALCULATION]) and then in two extra columns ([NO_TENURE] & [TENURE]) the same calculation but using “CASE WHEN” to filter the information based on another column called [TENURE], everything in one single line like this: Right now is being shown this way: This is the code I’m using: I really appreciate

MariaDB Case statement

I have the following SQL-Code in a Mariadb-Database: (1) I need the following result: If Matrix=’AW’ => I need the field “FaktorAW” else => I need the field “FaktorGW” is it possible to formulate Statement (1) with a “case statement”? Answer Of course, this is possible. Basically you can do this: You have to take care if this is really

show who resit and passed and what course was it?

i need help find who fail in exam & resit and pass the exam only, heres the code: heres the result: I need find like this: Answer Possibly using a query like below. this is using your query as input. Also we have assumed that it is not possible to have a student have (PASS, FAIL) for a student on

MySQL alternative way to `CASE` Statement

May I know, is there any alternative way or short way to write this case statement shown in the below: I tried using mysql built in funciton ifnull as below: ifnull(p.our_price,p.sales_price) But it doesn’t work for me. Answer You could stick with a CASE expression but use COALESCE to make it more succinct: Or, using the IF() function: As a

SQL: use CASE with AS

I’m working on a long SQL request and I want to use CASE inside but I don’t know how to write it. My request looks like : I want to add something like : I tried to add this at the end but it didn’t work : My goal is to edit key along its value Answer You can do

SQL CASE WHEN won’t meet condition

This is a solution to one of the leetcode problem. It is asking me to output the second highest salary from the table and if there are no second highest salary then the output should be null. The above is my solution. I used case and when syntax but the problem is that even when the table only has 1

Advertisement