Questions tagged [case]

In SQL, the CASE expression evaluates a list of conditions, returning the result for the first condition which evaluates to true. For programming languages' CASE questions, use the [switch-statement] tag instead.

8,809 questions
-1votes
0answers
8views

How to make a custom calculated field based on custom weekly calendar

I want to create a calculated field based on date that groups 8 consecutive days under a custom week. I don't know how to construct a case when/then statement without an invalid formula error. ...
-1votes
0answers
19views

Case_when in R with condition OR [duplicate]

I am trying to create a new column dependending on values of other columns (1 or 2 in any of the selected columns--> Usuarios; 3 or 4--> no_usuarios). Here is my attempt: Encuesta2022_completa &...
0votes
1answer
20views

using the code for different set of ranges

Situation Hello SO, I have a situation where, I have the following code which I would like to use over other ranges to. But in this case, when the case ranges changes, the clear contents and otehr ...
1vote
2answers
35views

SQL CASE in GROUP BY

I have a query that is meant to get the count of each reaction on a comment and whether the user is one of the people who made that reaction. However, my case statement returns includesMe:1 for EVERY ...
  • 67
0votes
1answer
29views

How to use a Case When Statement to Count a Count Column

SELECT DISTINCT f.location_name, COUNT (*) AS COUNT FROM fastfood GROUP BY f.location_name; Hi, What I want to do is count the Count column, so I can see specifically how many locations have a count ...
0votes
1answer
41views

Between genres, which type of movies seems to be more rated by age group?

how can i join three tables, find the most rated genre from genres and group them in age. i have already created the tables i did something like this, but i know is wrong SELECT count(CASE WHEN (genre ...
0votes
1answer
36views

How to use case statement when both conditions are true and you need to display only one as a result

query: SELECT DISTINCT userId, sessionId, CASE WHEN b.pageType ='confirm' THEN 'User_converted' ELSE 'Not_converted' END AS conversion_index FROM ( SELECT userId, ...
0votes
0answers
10views

Insert Into Select Case Statement

I am using an Insert Into Select to move a new table into a master table. I need to have either one of two columns [customMessage1] or [customMessage2] in the new table be entered into the master ...
-1votes
0answers
22views

SQL qgis 3.10 issues with case

So I'm trying to determine if there's trees planted on one/both/neither side of the river. I got 2 field for each side of the different rivers so i though i would be using select and CASE my script ...
0votes
0answers
43views

2 Counts and combining the results as one column | sql server management studio

Im trying to do a count of distinct Id's of people in a database based on some registrationdate and creationdate. tables: - people p - number n - message m - volume v Requirements In case of a ...
0votes
1answer
31views

How to get SQL output with more rows than original table? - Timeline of Events

I have a table as follows: event_num occurs_at_time length 1 0 10 2 10 3 3 20 10 4 30 ...
0votes
2answers
40views

Case expression

How do you write a case expression that has 2 conditions ? What I'm trying to say in the code below is when the color is red and the quality is bad then price. And when color is red but quality is ...
0votes
1answer
23views

Troubles with Case and Creating a table on SQL

I'm trying to create a table where I can pull the result of the winner of several games, I'm trying to use the CASE WHEN funtion in DBeaver but it seems not working, it seems to be a syntax error but ...
0votes
1answer
22views

Presto Case When In [closed]

I'm trying to use case syntax to determine if a campaign_id is in test or control groups, The issue is the combination of CASE, WHEN, and END. (Case and when works fine.) But I am getting the error: (...
-3votes
0answers
33views

how do I make Multiple cases statement when having 15 different case [closed]

15 Products each of them with a different value to return

153050per page