I have the following table: jan feb mar apr may jun jul aug sep oct nov dec 322 44 1222 These are invoice amount columns. They’re based off of the months of the year. What I’m trying to do is make a new column called execution window that will have different quarter values depending on where the amounts show up
Tag: case
SQL query to extract matching diagonal pairs in SQL Server database
I have a database table (mytable) with 2 columns x and y as shown below, from which I intend to extract rows with matching diagonal pairs of (x,y) and (y,x) e.g., 4 21 and 21 4 I have tried the accepted code on stackoverflow here (enter link description here) on my mytable which gives me the expected results on Oracle
SQL Query to use a Case Statement within and Aggregate Function
I have a query below that I need to get a count where Incident Records = 0. The first level is a summary of the records it grabs to calculate totals. I tried using COUNT(INCIDENTS!=’0′) but it apparently is not working though it does not error out. How would I get this count? This is in Snowflake if that is
Using SELECT subquery in a CASE statement and handling NULLS
I have 2 SQL tables one holding stock information then a style table which details how the stock is used. For some jobs the information is contained with a print file so the value in the stock table would be BIN, if not it would contain a template name which would cause a query to a Styles table which then
PostgreSQL: Return gaps and value mismatches between columns
Imagine the following data: I am interested in returning the entries where there is a gap in the data for a particular student, where the category changes from one year to another, or both. So the output that I’m after is: The reason why id 4 would not be returned is because there is actually no gap or difference between
A better way to get the last character
I have been working in an exercise, I have 2 values (one with 9 characters and the other with 8) and I have to show 3 columns. The original number The number without the last character Only the last character The Query works but I would like to know a way to improve how I get the last column, I
Multiple conditions in CASE WHEN statement
I’m working in SQL (Amazon Redshift) with Recruitment data where each applicant has multiple sources, which I’ve split into different columns called source_1, source_2, and source_3, along with a number_of_sources column to record how many sources that applicant has. We want each applicant to only have one source, and have certain rules to follow in how to select which source,
SQL divide row by row with the same column by using CASE
I want to create a new column which is to calculate the percentage, I know it can use subquery to do that, but is it possible to use CASE to do this? If using CASE how is the logic? Column A Column B Column C New Column that i want to create 2022-01-01 M0 72 72 * 100 / 72
Why is the else condition triggered when the when condition is fulfilled?
I take a number for customer type and a string for currency from the user and return the current row. If the currency entered by the user is not available in the table then I should return the row in which the currency value is ‘all’. And if the currency entered by the user exists in the table, I need
How do I take user inputs in CASE statements in SQL?
This is the query I’m trying to execute in SQL Developer, but I get an error: Error at Command Line : 2 Column : 7 Error report – SQL Error: ORA-00904: “INPUT”: invalid identifier 00904. 00000 – “%s: invalid identifier” Can anyone help me out? Answer As Alex commented, if you want to use that substitution variable twice, you’d rather