Background I have a Postgres 11 database running on RDS. I need to produce a report which shows counts of events over a certain period, grouping, renaming, and counting them based on description …
Tag: case
Case when date = current_date then text
I have a table like this: But when I execute this query: I get this result: SQL Fiddle I would expect that in the rows where is_equal is true, the result should be TODAY. What am I doing wrong? Answer Nevermind, I solved it, but I don’t want to discard the question. The solution is to CAST(token_date as varchar) in
SQL CASE Expression
I need to write a sql statement(Oracle) where I can withdraw data from two diff tables and check for a condition and return a certain string. My statement goes like this, When I run this I get a error: “FROM keyword not found where expected”and points to the c in line 2. and if I change the from to line
How to return only one row per course
I am trying to return a list of course IDs that contain three components: assignments, discussions, and a syllabus. I want my results to have only one row per course ID with either Y’s or N’s …
Swapping one column to another
There are n number of parent tasks and each task has their actual start time and actual end time, now there are child task as well, for one parent task which ends with ‘createprovision’ i want to replace the end time with the start time of the child task which starts with ‘Preparations’ Sorry I am editing the question The
‘Tagging’ a record using multiple criteria
I am using Presto. I want to assign a row with multiple ‘tags’ using different criteria that are not mutually exclusive. For example, let’s say there’s a table with 4 columns: | food | color |…
Creating extra columns based on condition (Case When Sum)
I have survey table where someone is asked roughly 5 questions. 4 of those questions are the same questions, but the options to their answers are different since they were to understand their purchase. Here are the questions: The goal is to create four extra columns based on their answer and they will be assigned a 1 or 0. Since
How to put Case in Where Statement for Oracle SQL
For the query below, I’m trying to pull a specific date range depending on the current day of the month. If it’s the 20th or less (e.g. “2/7/2020”) then I want the date range for January. Otherwise, I …
SQL CASE statement needs to handle Text
Apologies if this has been asked before – I’ve spent a couple of hours searching but not found anything that’s helped. It’s quite simple really – I’ve been asked to create a query which includes a field that when it was set up (not by me) was created as a VARCHAR instead of an INT. I need to do some
Convert result of CASE Expression to a number in Oracle SQL
I have the following select query. I want to convert it from string into a number. If I wrap a TO_NUMBER around the case expression, I get expression must have same datatype as corresponding …