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
Tag: case
[SQL CASE WHEN]Why case when is not working when I specify two conditions at the same time?
Hi I was trying to a different version of SQL query that I was given from datacamp. The query I was provided with is I tried to tweak it thinking, “instead of setting one condition for each case scenario, let’s set two conditions at the same time by connecting the two conditions with ‘and ” My query is as below.
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
SQL: How to combine values in column week (i.e. week 1, week 2, etc) into week range (week 1-2 or week 1, 2)?
General SQL question using online SQLite editor, if I have the following table: item week sales item1 1 35 item2 1 25 item3 1 24 item1 2 35 item2 2 34 item1 3 24 item2 3 45 item1 4 44 item2 4 51 item1 5 1 item3 5 100 how would I get the output to be this: item weeks
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
Using if-then or case-when-then to select from dataset
I have a dataset with students in 1st, 2nd and 3rd grades. I want to select the names of all students in 1st and 2nd grades, but only students named John, Jane or Smith from 3rd grade. Here is what I have so far: I’m not sure what I’m getting wrong there but I’d appreciate some help. Thanks Answer You
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
SELECT from Multiple IF conditions in Where Clause
I have a following query In the above query I need to add IF condition that IF a.Type is Accessories then I need certain a.Brands to select from and if a.Type is Clothing then I need to select from certain a.Brands Answer Use a CASE expression, but you should also write a proper join with an ON clause for the