674,322
questions
0
votes
1
answer
9
views
Why does the query using SYSDATE to fetch the most recent date from the commandes table return no results?
SELECT *
FROM commandes
WHERE EXTRACT(MONTH FROM datecommande) = EXTRACT(MONTH FROM SYSDATE)
AND EXTRACT(YEAR FROM datecommande) = EXTRACT(YEAR FROM SYSDATE);
I need to return data from 2020, but ...
0
votes
0
answers
18
views
Cumulative sum with group by
I have a table with financial transactions, and want to create a running total per day. Is this the correct way to do it? Is there a better way? It seems to work, but I could not find this specific ...
-2
votes
0
answers
11
views
How to combine this two table data in a single result set with CTE
Query#1
WITH Devicerank
AS (SELECT t.CHANNEL,
t.user_id,
t.device_name,
t.device_id,
t....
-2
votes
0
answers
21
views
I need help writing this excel file into PostgreSQL using the Query Tool [closed]
text
CREATE TABLE wearable_devices (
Brand_Name VARCHAR(100) NOT NULL, -- Brand name of the device
Device_Type VARCHAR(50) NOT NULL, -- Type/category of the device (e.g., Smartwatch, ...
1
vote
2
answers
31
views
NULL Values For Unmatched WHERE
Say I have a table with dates and associated data for each date. I want to select every date, but only show the associated data if it matches a WHERE clause, otherwise just fill it with NULL. The goal ...
2
votes
0
answers
44
views
How to use list of pairs as parameters for a query in postgres
I am using java spring boot with postgres as my database. I have a table called current logs with many fields. I also have 2 lists one for team ids and one for event dates. Now team_id[0] corresponds ...
-1
votes
0
answers
15
views
Find users that appear again after not logged in for certain period of time [closed]
I have BigQuery table that contains daily activity of user terminals that appear in certain region. Database contains about 3 years of daily records. The table has day field that signifies the ...
0
votes
0
answers
28
views
Managing 4 billion rows of data in SQL Server on multiple partitions [migrated]
I have a table with over 4 billion rows. All of the data is time bound down to the datetime stamp over 41 partitions - each partition is bound by the YYYY-MM. Partition 1 is timebound from let's say ...
0
votes
2
answers
18
views
Oracle query question related to filtering criterias
Here is my oracle table
Department Table**strong text**
department_id varchar(25) primary key,
employee_id number,
occupation varchar(25)
salary number
as_of_date date
Data is as follows
...
-1
votes
1
answer
47
views
why the combined SQL query is slower than the one broken into parts?
I have two queries. They both do the same thing. However, the combined query (the first one) runs a lot slower than the one which is broken down into pieces (the second one). Does anyone know what is ...
0
votes
1
answer
18
views
Stored procedure in snowflake to convert all views to table
I have created a stored procedure that can convert all views from a schema into tables in another schema but it simply does not run in Snowflake.
CREATE OR REPLACE PROCEDURE COPY_VIEWS_TO_TABLES()
...
0
votes
1
answer
14
views
How to create an array by replacing values from another array?
I am looking for a way to create an array from another array based on the values of the second array with value mapping.
E.g.
Table A has columns id, some_array
and I have some value mapping in mind, ...
0
votes
1
answer
24
views
SQLite constaint for making 2 columns different
I have 2 SQLite tables, users and transactions where a "transaction" happens between exactly 2 users.
A short example would be:
CREATE TABLE users(
id INTEGER PRIMARY KEY ASC
);
CREATE ...
0
votes
1
answer
26
views
How to filter results in SQL tables when number of columns is not the same in different tables?
We worked to create a table in SQL and we need to create a function which filters results based on the event.
However festivals contains only 5 columns and concert contains 6 columns.
This throws an ...
0
votes
2
answers
17
views
SQL query help for data checking two tables in Snowflake
I have table A with column appleId.
I have table B with column bappleId.
Creating a row in table A should create a row in table B where appleId = bappleId.
Table A
Id
appleId
3
33
4
34
5
35
6
36
...
0
votes
1
answer
28
views
Grouping a table by its type on different columns
I have a table with two columns (type, id) that has the following structure:
id
type
A123
ACCOUNT
C123
CLIENT
O123
ORDER
A124
ACCOUNT
O124
ORDER
C125
CLIENT
I want to be able to do a SELECT on ...
0
votes
2
answers
22
views
How to get Postgres full JSON path from jsonb_path_query
I need to update jsonb column by jsonb_set, to use jsonb_set, need a full Json Path. How could I get full jsonb path when jsonb has list?
For example, I got a JSON :
{
"Laptop": {
&...
0
votes
1
answer
26
views
Oracle SQL - Recursive Query?
I am attempting to write a query that will return a distinct count of order numbers where the part (and then corresponding parts) can be found.
Columns: ORDER_NO PART_NO AMOUNT
A ...
0
votes
0
answers
43
views
SQL query that returns results that have all tags, not any [duplicate]
I have three tables:
A table of plays (tbl_plays), a table of possible tags (tbl_tags), and a table of applied tags (tbl_tagged) each play may have one or more tags applied to it e.g.
'Three Blind ...
1
vote
2
answers
57
views
"union" to avoid duplicates
https://dbfiddle.uk/zspUa8WK
I need to export name and sum the invoice of my customer since 2022. So I need to get only customers which bought since 2 years and the sum.
No problem for that:
select i....
0
votes
0
answers
26
views
Why am I getting blank rows from CASE statements when first statement returns value [closed]
I am attempting to write a query that uses multiple "CASE WHEN" to count instance for different categories.
What I have now is this:
SELECT COUNT(CASE WHEN customer_feedback = "Very Bad&...
-3
votes
0
answers
28
views
Sort query results in different columns in SQL [closed]
I have a query that gives me diferent results for the same profile:
SCALE_PROFILE
VARNAME
VALUE
1
SCALE_PROFILE
SCALE_COM1_ID
1
2
SCALE_PROFILE
SCALE_COM1_IP_ADR
noname
3
SCALE_PROFILE
...
0
votes
1
answer
64
views
PL SQL calculate delta and transpose the result
I'm using PL SQL and I have the following sample data:
(I have an ID and an accumulated daily counter, assuming I need to check only recent 7 days (Nov 26th till Dec 3rd in this case))
I want to ...
-1
votes
1
answer
36
views
Left join but use group by field that on right table [duplicate]
I have two tables, first one has detailed order information.
Table A: Restaurants id, brand id, date, order id, order value (usd)
Table B: Restaurants id, restaurants name, brand name
I want to ...
-2
votes
0
answers
23
views
How to exclude specific rows (e.g., deleted items) from filter dropdowns? [closed]
I’m working on a dashboard in Metabase and need to set up linked filters. One of my filters is based on a column from a table that includes rows marked as deleted by using the "deleted_at" ...
0
votes
0
answers
12
views
Stripe Sigma - Connecting transfers to transfer reversals
I am writing a query on Stripe Sigma, to route transfers via Connected Accounts.
For context, the money from customers comes into our main stripe, we then transfer the relevant amount to the ...
0
votes
0
answers
28
views
ms access sql with validity check violation [closed]
in MS ACCESS I am trying to update two columns with respect to a clear identifier (IDFF). Both tables have 475 rows, and the IDFF is clearly unique. The first column (A1_5_1) is filled completely, the ...
-4
votes
2
answers
40
views
Query to only return parent table if all subquery has multiple conditions true [duplicate]
I want to ONLY select customers who have purchased both products 22 and 36
Customers
Id
Email
Name
1
[email protected]
Jack
2
[email protected]
Robin
3
[email protected]
Pop
Sales
Id
CustId
ProdId
Amount
...
0
votes
1
answer
26
views
JPA Criteria API and parentheses
I have the following JPA Criteria API method:
public List<AggregationTask> findNonExpiredTasksBy(String entityName, Map<String, String> columnValues) {
CriteriaBuilder cb = ...
0
votes
0
answers
40
views
Extracting data from an earlier record
select
ppc
, toDate(if(work_hour < 6 and work_hour >= 0, toDateTime((`history.ppc_action_date`) + 3600) - interval 1 day,
toDateTime((`history.ppc_action_date`) + 3600))) ...
0
votes
2
answers
63
views
Query to Count Records in a 1-Hour Sliding Window
I have a table where each record represents a transaction by a user. I need to find out if any user has inserted 1000 or more records within a 1 hour time window on a specific date. For example, if a ...
0
votes
5
answers
84
views
Query to check status change of an item
I have a table dbo.tblPresentationStatus (SQL script for table at the bottom).
I have to select rows where the status change is wrong. Correct flow
is as below:
Review --> Approve --> ...
1
vote
1
answer
60
views
Two select statements in one Query
I'm new to SQL and I'm having trouble with a pretty basic problem. I have a with column: "primaryProfession" in this column there are actors and actresses. I want to return a result that ...
-3
votes
0
answers
23
views
How do I master SQL joins and nested queries? [closed]
How do I master SQL joins and nested queries?
0
votes
0
answers
19
views
Amazon QuickSight | Recursive CTE in subquery are not supported
I would like to use a recursive CTE to generate a series of dates. I am using this CTE to cross join onto locations to generate a mapping table as a CTE where each location has a row for each date. ...
0
votes
1
answer
47
views
Better way to return rows WITHOUT a left join match? [duplicate]
We have two tables - Table1 and Table2 - in a SQL Server database, and we are trying to identify rows in Table1 that do not have a match in Table2. Right now, this is accomplished using nested views:
...
0
votes
2
answers
29
views
Unpivot snowflake table with pivot column alias
I got the following example of how to unpivot Snowflake tables:
SELECT *
FROM monthly_sales
UNPIVOT (sales FOR month IN (jan, feb, mar, apr))
ORDER BY empid;
This is very nice, but I need the ...
1
vote
1
answer
43
views
Using Aggregates on Multiple related tables removes rows without relation
I have a postgresql database I am trying to query and this is my current code:
SELECT r.id, r.band_id, r.title, r.imageURL, v.rating, b.name AS bandname, l.price
FROM records r
...
0
votes
4
answers
75
views
Making the SUM clause specific to a given field
I'm trying to get a ratio of 'Good' values to the Total for a given ID. The query below works when I only use one ID for the IN clause. However when I add more than one ID, the Total ends up being ...
0
votes
4
answers
75
views
Cleaner way to write a CASE WHEN when entering different data for a column?
I added a new column named fledgling and I am trying to add the data in this column.
ID
birdname
height
wingspan
eggs
broods
incubation
fledgling
nestbuilder
1
Great Blue Heron
52
78
5
1
28
NULL
B
...
-1
votes
4
answers
90
views
How do I merge two LEFT JOIN rows that cannot coexist into one?
So I have a result like this gotten from multiple LEFT JOIN statement where one join is available, the other is null
user_id | country | purpose_id
2 CA NULL
2 NULL 367
2 ...
0
votes
1
answer
53
views
Finding the linked orders data in sql
trying to find the chain of orders using SQL query joining below two tables. If one order is dependent on two orders then the baseline order will be the one with minimum created_date.
Order table:
...
1
vote
1
answer
20
views
Django Query API select_related in multi-table count query
Imagine I'm trying to count the number of tree cultivars in a certain park, and the trees are grouped in specific fields within the park. One catch is that trees can be replanted, so I want to count ...
0
votes
1
answer
38
views
Flyway DB Script spelling mistake
I have a Flyway script that creates a new table to store reporting data to another table's data.
I made a mistake cutting & pasting from a Java object and as you can see in the script below, the &...
1
vote
2
answers
47
views
How do I display staff who are not on annual leave?
I am trying to build an annual leave program.
I have two tables the first one stores all the staff data and the second one contains the staff who are on annual leave with their start and end date.
I ...
-1
votes
0
answers
43
views
Dirty reads happening in RCSI in Azure SQL Server
Although my database isolation level is set to READ_COMMITTED_SNAPSHOT, I am still getting dirty (uncommited) reads.
SELECT COUNT([random_string]) NoTx FROM [dbo].[IncTesting5];
BEGIN TRANSACTION;
...
0
votes
0
answers
21
views
Combine grouped columns into one row [duplicate]
My current data looks like the following:
Claimnumber TaskName CompleteDate GroupNum
123 Claim Creation 2024-01-01 1
123 Incoming 2024-01-05 ...
-3
votes
0
answers
39
views
Insert data through Excel to an existing SQL table using power query
I am working on a little PowerQuery project.
Insert data manually into an Excel table
When Enter or refresh this data get updated in the existing SQL table
Clear the Excel table for the next entry
...
0
votes
2
answers
53
views
Extract parts from sql sentences with pyhton script
I have a .sql file with CREATE TABLE AND INSERTS TABLE sentences in it.
Example:
INSERT INTO `examle` (`myid`, `title`, `value`, `usefull`, `picture`, `short_description`, `description`, `wikipedia`, `...
0
votes
0
answers
38
views
Best practices for referencing tables in Azure SQL Server with multiple databases [closed]
I am working with an Azure SQL Server hosting multiple databases (db1, db2) each containing similar tables named like table1 within schema1.
In my stored procedures, I've been referencing tables like
...