Questions tagged [query]
Writing queries to request or change information stored in a database or other information management system. Questions should include table and index definitions, sample data, expected output, and a tag for the specific system (e.g. MySQL, PostgreSQL, Oracle, SQL Server, MongoDB).
1,579 questions
0
votes
2
answers
58
views
PLSQL query to return the trackingcodes only if all its cashout_trackingcodes belong exclusively to that trackingcode
I have a table with below structure:
create table TEST_REFUND_CASHOUT
(
f_gdate DATE,
trackingcode VARCHAR2(4000),
cashout_trackingcode VARCHAR2(4000),
cashout_date ...
0
votes
0
answers
54
views
SQL Server 2022 CU11: Specific CPU Cores Constantly Spiking After Plan Cache Fills
We have observed an unusual CPU behavior on our SQL Server 2022 (Core Edition) starting from a specific date.
The issue is that a few specific CPU cores — particularly cores 1, 7, 14, and 21 — ...
0
votes
0
answers
28
views
How to write a query from one table with dynamic row and column headings [duplicate]
Apologies if this is a basic question, but my google isn't googling, and SQL is not my strongest point.
I'm trying to create a table output in SQL where the headings and rows are dynamic.
I'm trying ...
3
votes
1
answer
188
views
Merge two queries into one, involving aggregation
I have these two queries in Postgres.
One is:
SELECT _id, created_at
FROM pedidos
WHERE _id = '123abc;
Works fine, returns:
{
"_id": "123abc",
"created_at": &...
0
votes
2
answers
105
views
PSQL: passing variables into a select 'create user ... ' subquery
In Postgres I'm trying to automatize the creation of a non-existing db-user (using it in Debian's postinst script) in the following way:
SELECT 'CREATE USER :v1' WHERE NOT EXISTS (SELECT FROM pg_user ...
1
vote
2
answers
93
views
Sql Server: Query assistance to retrieve count in two different groupings within a dataset
We have a dataset with "visits & events" with their "frequency". Sample data looks like this:
DROP TABLE IF EXISTS dbo.EventMetrics
GO
--
-- Create table with sample dataset
--
...
1
vote
0
answers
83
views
Looking for a query to get a view's referenced columns in another database
Getting the referenced columns from a view that references data to it's own database if pretty straightforward with the INFORMATION_SCHEMA.VIEW_COLUMN_USAGE-tables but I'm struggling with getting the ...
2
votes
2
answers
67
views
Collate a query result column with a simple list?
I have many queries that return some statistical data on a subject in various tables. The result includes a "classification" that is one of {"C","P","M"}. I ...
0
votes
1
answer
56
views
Database / Search-Index recommendation: Match time ranges from different categories
300k+ videos
10+ millions of markers, pointing to timeranges in videos
{
"markerCategory": "something",
"markerDesc": "something-more-specific",
"...
0
votes
1
answer
64
views
Removing chronological duplicates from history table in SQL
I have a history table, I want to create another view to pick relevant records from this history. Not all records are relevant. I'm after the record changes for certain columns, for this case I care ...
0
votes
1
answer
108
views
How to retrieve only the elements of the array that satisfy the conditions of the query in MongoDB
I am very new to MongoDB and have just started learning and working with it. I have a question about a query. This is the query:
db.getCollection("user_plates").count(
{
"...
0
votes
1
answer
74
views
Better approach to 'pivot' the data of a table
I have a table with below structure:
create table test_table
(queuename number,
duration_sum number,
rating_sum number,
rating_avg number,
rating_cnt number
)
Here is the sample data:
...
3
votes
2
answers
465
views
Variable SQL join operator using case statement
I have a fact table that contains sick leave values for employees (Table 1) and I need to slot each value into one of the bands (Table 2)
The problem is that the fact table contains some negative ...
0
votes
2
answers
76
views
Guarantee SQL Management Studio Query
When running a query in SQL Server Management Studio, is it then possible to guarantee that the script will only target the designated database?
When I select a database, that's fine and good and all -...
1
vote
2
answers
90
views
Sql Server: Query to parse and validate codes
We have a #ValidCode table with list of valid codes like: 'A', 'B', 'C', etc. Another table called #SourceData with input data -- that comes as a combination of valid and invalid tokens (sometimes ...