9,749 questions
1
vote
1
answer
75
views
Creating Materialized view in PG 17 ignores data types in SELECT
I have the following SQL to create a materialized view and the SQL seems reasonable to me but it's unclear from Postgres docs what should happen in this case.
I am listing the columns when creating ...
-1
votes
1
answer
54
views
Improving performance on left join condition with CASE in Snowflake [closed]
I have a view which extracts data from two other views, joining on ID and date columns.
WITH CTE A AS
(
SELECT *
FROM TABLE A -- A UNION OF SEVERAL TABLES
),
CTE B AS
(SELECT *
FROM TABLE B
WHERE ...
1
vote
1
answer
156
views
Issue with Cast in SQL Case expression - not working properly
I am using SQL Server 2017 and I am writing an UPDATE statement with a CASE expression. In the update statement I am having an issue with the calculation. It is a simple calculation when I cast the ...
4
votes
1
answer
114
views
Why do I get an "invalid identifier" error when I use LEFT()? [duplicate]
From a 6-character string in TERM_CODE_KEY I need to produce a calculated result as column academic_yr:
-- TERM_CODE_KEY is of type VARCHAR2(6) and returns values of the form YYYYMM
SELECT ...
-1
votes
2
answers
79
views
SQL code for identifying salary for a status
I have 2 tables:
DEPT:
dept_no
C
N
1
200
100
2
300
150
3
400
200
and EMP:
dept_no
employee_no
Task_status
Salary
1
1
C
1
2
N
2
1
C
2
2
C
with column Salary has to be calculated. Task status is C is ...
1
vote
1
answer
121
views
Extended condition of aggregating functions SQL
I need group speed by ram and return MAX(speed), where at least one NULL in speed values will return NULL.
ram
speed
128
600
128
600
128
750
128
750
128
800
128
900
32
400
32
NULL
32
500
64
450
64
500
...
0
votes
1
answer
91
views
How can I use the COUNT and GROUP BY along with the CASE commands in SQLlite to show the number of students with each letter grade?
I am trying to use the SQL commands COUNT and GROUP BY to show the number of students with each letter grade, but I'm having difficulty in doing so. A new column that I created contains a letter grade ...
-1
votes
1
answer
114
views
Is checking the requirements for ISNUMERIC() happening before evaluation of the CASE WHEN logic
Consider this
SELECT
CASE
WHEN 1=1 THEN 1
WHEN 1=1 THEN 1/0
END
This returns 1. A clear example of how the WHENs are evaluated in order.
However, when I do this:
DECLARE @...
1
vote
3
answers
103
views
SQL query to aggregate and count non-null values across multiple columns
I have the following database schema. It looks at shoppers and how many orders they have made from three websites in a network.
ID
Name
Country
website1_Orders
website2_Orders
website3_Orders
123
...
1
vote
2
answers
100
views
Create a new column based on values in the same table
This is an idea of how my table looks -
no
country
language
translatedName
1
c1
en
test1EN1
1
c1
l1
testL1
2
c2
en
test1EN2
2
c2
l2
testL2
This is how the data might look like where a country can have ...
-2
votes
1
answer
59
views
10.4.32-MariaDB mysql conditional join horrible performance [closed]
I have a query that uses a conditional join similar to the code snippet below. The join is different depending on whether or not parameter _search_string is null.
Even when _search_string is null, ...
0
votes
1
answer
161
views
Retrieve the value of an input expression from within a case expression in T-SQL
Consider this form of a case expression:
CASE [input_expression]
WHEN [when_expression] THEN [result_expression]
...
ELSE [result_expression]
END
And this example of that form:
CASE db....
0
votes
1
answer
67
views
How can I return values from multiple columns as well as 'Yes' or 'No' to show that another value is or is not present?
I'm trying to pull data relating to a certain type of customer ID. For one of the columns, I need to know only whether there is a value present or not, while still returning all values for the rest of ...
1
vote
1
answer
76
views
SQL Query in Snowflake - Calculate Days of Supply
I tried to find the days of supply each day. For example, date 1/23/2025 - It has inventory 700 which already subtract the forecast, 400 on that day. Count how many date of forecast can be covered by ...
1
vote
1
answer
50
views
Separating fields in the same column
I need to separate items in a column to show in the same row but having trouble coming up with the query to get this done
For example, here is how the table shows below currently:
person_id
...
2
votes
1
answer
92
views
How to pass a case of type "function" as a parameter?
I've been using Codable enums to encode my classes to JSON, and I've hit a roadblock:
enum MyEnum: Codable {
case case1(data: Data)
case case2(str: String)
case case3(url: URL)
}
// .....
-2
votes
1
answer
74
views
CASE query to get results from different tables [duplicate]
I am working on restaurant project. The restaurant takes online orders and "in restaurant" orders
I need to print out all active orders with 1 query. The problem comes when I need to ...
1
vote
3
answers
84
views
SQL for returning number of days since last availability, grouped by category?
I'm using SQL and I have some dummy car dealership data that for a given dealership tells me whether a particular make is currently being sold there, and if not, when the last time that make was ...
1
vote
1
answer
103
views
PostgreSQL Case with a subquery using a different where clause
I am trying to query the correct price by going through and choosing between 2 prices.
These are in order of importance from highest to lowest:
if [tran_type] is equal to Quot than choose this price
...
0
votes
2
answers
66
views
SQL Case Statement selecting data [closed]
I'm working on my first SQL case statement - and unsure how to do this.
I have two different columns of data, one is for drive A, the other drive B.
I want to select data from drive A for display ...
-3
votes
4
answers
129
views
I am trying to get the start date ONLY from the column below using a SUBSTRING. Can someone tell me what I'm doing wrong?
This is what I have so far:
DECLARE @STR AS VARCHAR(1000) = 'CustomerID #101010 added. Fixed Price: 3.5555 Effective from 10/16/2024 to 03/31/2 SADFGZFGDA025 Deliveries: 100 Company Pricing Program: ...
2
votes
2
answers
224
views
Polars SQL CASE
Is this a bug, non-conformant behavior, or standardized behavior? A Polars SQL statement is calculating the average of values based on a condition. The CASE WHEN doesn't include an ELSE because those ...
2
votes
2
answers
94
views
How do I check if a macro was run before proceeding with a different macro?
I am learning VBA and attempting to automate a report that has multiple steps.
Step 1 - Click Button #1 to run a macro with a series of formulas based on input data provided by the user.
Step 2 - ...
1
vote
1
answer
475
views
Effect on synthesis when adding default to a unique case
In System Verilog, I want to instruct the synthesizer to infer a parallel check of some conditions, thus I am using a unique case. I am also adding a default statement. What I would expect is the ...
-1
votes
1
answer
75
views
GROUP BY is not working with multiple Case Statements and a Left Join
I have two tables I am trying to write a GROUP BY clause with multiple CASE statements so that the data will be grouped into one row for each client instead of multiple rows for each client.
Here is a ...