673,433 questions
Score of 1
1 answer
83 views
An empty alarm-threshold lookup errors globally but returns NULL when correlated
This is the smallest alarm-threshold lookup I can reproduce:
CREATE DATABASE alarm_thresholds;
USE alarm_thresholds;
CREATE TABLE limits(station STRING TAG, threshold INT32 FIELD);
INSERT INTO limits(...
Score of -3
1 answer
100 views
Compose foreign key from multiple tables
Let's suppose I have this model:
TableA (
Col1 int,
Col2 int,
Col3 int,
Primary key (Col1, Col2)
)
TableB (
Id int,
Col1 int
)
TableC (
Id int,
SubId int,
Col2 int,
Primary key (Id, SubId),
...
Score of 2
2 answers
151 views
CAST fails when included in SELECT, works if outside of it
I am trying to extract the largest used serial numbers from a table of multiple products. The numbers are stored as varchar(50). One of the serial numbers includes a letter P suffix, so I use this to ...
Score of 0
1 answer
149 views
How to change the query with a number of records condition in all groups and with the sum for a specific column?
My script:
-- DROP TABLE IF EXISTS test;
CREATE TABLE IF NOT EXISTS test
(
id smallserial,
date_pr date,
num smallint,
naim text,
pr numeric(19,4),
txt text,
CONSTRAINT ...
Score of 1
2 answers
185 views
Optimize query to get row-based data with lots of attributes?
I have a stored procedure in SQL Server, which is query a row based table.
SELECT csd.*
FROM MyData csd
INNER JOIN #AttributeIds id ON csd.DataAttributeId = id.ResidentialAttributeTypeId
WHERE 1 = 1
...
Score of -1
3 answers
214 views
DBeaver community edition: How to hide columns that are all NULL in the result
I would like a generic way, either in the tool of in SQL to show only non-NULL values in my results. In the example below select * from inventory.element, I would like a way to hide clei, description, ...
Score of 3
1 answer
207 views
SELECT SQL query returning no columns
The goal is to find a way to return no columns for an arbitrary SQL query.
Rationale: curiosity; it should not be possible by definition.
By "no column(s)" it means zero columns (no constant,...
Score of 1
2 answers
216 views
Verify the integrity of a junction table data
I want to verify the correctness of the data inside a junction table.
Here's a minimal example - table Products:
Id
EnglishName
1
Drill 4
2
Light Switch 48
Table Suppliers:
Id
EnglishName
1
Bosch
2
...
Score of 2
1 answer
290 views
Why does adding ORDER BY time DESC cause the query to return no data?
In Apache IoTDB 1.3.7, why does adding ORDER BY time DESC cause the query to return no data?
This query returns data:
SELECT *
FROM root.iot_prod_2.p.cjzxjd.t0020.ori
WHERE time >= 1791625620000
...
Score of -1
7 answers
311 views
Select only if ID value is X and no other value [closed]
How do I select the ID's that have only the colour 'Red' and no other colour:
ID
Colour
1
Red
3
Blue
2
Red
4
Red
1
Yellow
I am trying to write a SQL WHERE clause that returns only IDs coinciding with ...
Score of 2
1 answer
230 views
Is there a standard way to deal with columns whose value is rarely different from the default? [closed]
Normally, whenever I have a table that has a column with values that are rarely different from a default value, I create another table that defines that column and references the original table, so as ...
Score of 1
2 answers
152 views
How to combine pivot table columns?
I have created two separate temporary tables for ticket and sales per TPM using SQL Server.
For tickets:
select *
into #pivotticket
from
(select [month], [ID],[TPM], [day], [Tickets]
from #...
Score of 2
3 answers
238 views
Canonicalising unit names from a flat file in a normalised database structure
I populate my table original from a CSV file and generate a 1-column primary key:
CREATE TABLE original
( value real,
unit varchar
);
COPY original
FROM 'projections.csv'
WITH DELIMITER ',' ...
Score of -10
2 answers
191 views
For SQL, how to use CONCAT [closed]
When writing a query, in what situation would I use CONCAT?
Score of 16
1 answer
1032 views
Why does Oracle return rows with EXISTS AND NOT EXISTS contradiction
I noticed that a certain view did not behave correctly when called within a NOT EXISTS and found out that the same view returns a row on this contradictory query, even though one would expect that ...