Skip to main content
Filter by
Sorted by
Tagged with
0 votes
2 answers
80 views

I am querying a database from a table of product IDs and location codes, stored in the nested format below. I'm trying to write a query to filter for only products that exist in the location South3. ...
Tyler Moore's user avatar
1 vote
0 answers
58 views

I have the following query statement, but why the on true is required is unclear. [question] id text 1 Boba Fett is a... [question_option] id question_id text correct 1 1 Jedi false 1 1 Sith false 1 1 ...
sonooby's user avatar
  • 41
0 votes
1 answer
118 views

With this data: create or replace table test_json as select parse_json('{ "include": [ "x", "y", "z" ...
archjkeee's user avatar
0 votes
0 answers
66 views

I have 2 tables (defined as models in python): Productions and Tasks. A Production can contain 1 or more Tasks. Tasks have a name (string), a priority value (int) and a state (TODO / ACTIVE / COMPLETE)...
123Hovedpude's user avatar
0 votes
3 answers
688 views

I am dealing with a PostgreSQL (v14) query of this kind SELECT ..., EXISTS ( SELECT 1 FROM table2 t2 WHERE t2.fk = t1.id AND LOWER(t2.table_name) = 't1' ) ...
Luca Blanchi's user avatar
0 votes
1 answer
82 views

Hello I am having problem with postgresql lateral join. My query is this: SELECT * FROM foo LEFT JOIN LATERAL (SELECT tsrange(now() at time zone 'utc', expiration_date) as time_range) ...
kluzamic's user avatar
-1 votes
1 answer
75 views

This is how it currently works, first select query returns a list of parameters. SELECT character_id, foe_id, location_id, date_time, damage, points FROM events ORDER BY date_time DESC LIMIT 100 ...
Mario Orozco's user avatar
2 votes
1 answer
98 views

Using PostgreSQL 16.2, I have two tables: task_pool table create table task_pool ( task_id serial primary key , order_id integer , user_id integer , expire_time timestamp , status integer default 0 )...
EyeDunno's user avatar
0 votes
0 answers
66 views

The doubt arises from a scenario like this: I have a table named one_table that has many related rows in another table named another_table, via foreign key like this another_table(one_table_id) ...
Victor's user avatar
  • 3,998
1 vote
1 answer
125 views

I try to understand LATERAL JOIN with this query: select m1.contributor_prescription, derniere_publication.date_publication_prescription from activite.metadonnee m1 left join lateral (select ...
Leehan's user avatar
  • 177
0 votes
1 answer
152 views

SELECT category_tree_master__."category_id" AS category_id, --searchchildrenmaster.children, --ARRAY_CONTAINS(category_product_nb_stand_nb_product."category_id" ::...
said oussema's user avatar
0 votes
1 answer
101 views

I have a dataset of points of different types. For every point in the dataset I want to find the closest point in every category. I can achieve this but the compute time is very long and I'm ...
Edward Brown's user avatar
6 votes
2 answers
4k views

I have rewritten the below query from using a correlated subquery to using a LATERAL JOIN. It is now faster, and I would like to understand why? This SO answer says that there is no golden rule and ...
Marnix.hoh's user avatar
  • 1,972
0 votes
1 answer
837 views

This query is for a Tableau dashboard. The users want to see the active clients in a sector as well as the contacts at those firms and how the composition of the data changes from quarter to quarter. ...
plankton's user avatar
  • 335
6 votes
2 answers
4k views

How does ON predicate of Postgres LATERAL JOIN work? Let me clarify question a bit. I've read the official documentation and a bunch of articles about this kind of JOIN. As far as I understood it is ...
Nikita Glukhov's user avatar
0 votes
1 answer
101 views

I have working code using PySpark which uses the STACK function to turn columns into rows, creating a display_name column in doing so. I am trying to convert this to a Snowflake query, in theory my ...
Jamie Tilma's user avatar
0 votes
2 answers
343 views

so I have two tables, A and B. first I do a lateral join of A with one column (items) select A.id, item->>'id' as item_id, b.id from a, jsonb_array_elements(items) rx(item) then I do a right ...
dexian's user avatar
  • 187
1 vote
1 answer
420 views

I am trying to get the syntax for a series of lateral joins in Oracle. I have an authors table with the author’s id, name and home; I have a books table with an id, authorid which is a foreign key to ...
Manngo's user avatar
  • 17k
0 votes
0 answers
52 views

I am trying to join data from two tables by nearest earliest date. The first tables dates are more frequent than the seconds dates. I came across a few links and it seems like a Lateral Join may ...
AKA_Tom's user avatar
  • 95
0 votes
2 answers
64 views

I am running the following cross apply sql query, however, the query cannot find the table. For example: SELECT sport,event_names FROM table_name t CROSS APPLY ( VALUES (event_1), ...
Stackcans's user avatar
  • 351
2 votes
4 answers
367 views

Here are the exemple tables: Product Prices (prd) start_date product price 2023-04-01 prod_A 10.0 2023-04-15 prod_A 20.0 2023-04-01 prod_B 20.0 Order Products (ord) order_date id product 2023-04-01 ...
Alvaro Santos's user avatar
1 vote
1 answer
86 views

I have a subset of a table: -- Subset +---------------------------------+---------+-----------+--+ |date_time |animal_id|location_id|id| +---------------------------------+------...
Shmookoff's user avatar
0 votes
1 answer
543 views

I've a below result set. Id Name Age 1 abc 3 Required Result: Id 1 Name abc Age 3
Aamir Khan's user avatar
0 votes
1 answer
200 views

Background I have a select statement that churns a bit. For sheer simplicity sake, we'll say it looks like this: select AllTheThings, AndThenSome from T1 The output looks like this: AllTheThings ...
SaintFrag's user avatar
  • 353
0 votes
2 answers
151 views

I have a table which has only one row like below, Here I want to convert the column names to one column and the row into another column, with the column names converted to some predefined numbers as ...
Ames ISU's user avatar
  • 417
0 votes
0 answers
69 views

Would like to know what is LATERAL and why LATERAL in SQL? Have few question to understand more on LATERAL. I searched in google and not getting clear understanding of LATERAL. Why Lateral Advantage ...
Learn Hadoop's user avatar
  • 3,058
0 votes
1 answer
624 views

I have used outer apply to pull the most recent careID and diagnosis date and then used aggregation function to count the total. The code worked, however as soon as I added another join which is: ...
user avatar
0 votes
2 answers
106 views

I have been trying to solve how to test conditions in two different rows, and put the results into one singular column without duplicating rows. I need to get the results in a way that pick the team ...
Camila's user avatar
  • 1
1 vote
2 answers
185 views

I have a query like this: SELECT DISTINCT 'EntityName' AS [Column], EntityName AS [Value] FROM dbo.Deals WHERE EntityName IS NOT NULL UNION SELECT DISTINCT 'AssetClass' AS [Column], AssetClass AS [...
Peter Olson's user avatar
0 votes
2 answers
50 views

Simplifying a bit. I have the following data structure: | id | name | traversal_ids[] | | -------- | -------------- |-----------------| | 1 | container1 | {1} | |...
Alex Serban's user avatar
0 votes
1 answer
415 views

Below is the given table. date id1 id2 fact boolean 2022-01-01 i1 l1 100 0 2022-01-02 i1 l1 10 1 2022-01-03 i1 l1 110 0 2022-01-04 i1 l1 70 0 2022-01-05 i1 l1 20 1 2022-01-05 i1 l1 30 1 2022-01-06 i1 ...
Mahesh Shankar's user avatar
2 votes
5 answers
99 views

I have two table,the names table and the earnings table. Name_ID Name_desc 1 mark 2 smith 3 becky 4 jimmy and the earnings table ID_1 Earnings_1 ID_2 Earnings_2 ID_3 Earnings_3 ID_4 Earnings_4 1 500 2 ...
Petersselorse's user avatar
-1 votes
1 answer
40 views

I am trying to understand the best way to merge a count from an INNER JOIN of two tables and grouping, but the best thing I can do is to query each table separately and then apply a union and further ...
StefanM's user avatar
  • 63
0 votes
1 answer
136 views

I have the table in below format : id year column1 column2 column3 1 2000 10 20 30 1 2001 100 200 300 I want the transformed version to be like - id Field value_2000 value_2001 1 column1 10 100 1 ...
martin's user avatar
  • 3
1 vote
2 answers
2k views

I have a table that looks like below: ID DATE_OPENED DATE_CLOSED STATUS TREATMENT 1 2022-12-05 2022-12-05 Notification Control 2 2022-11-24 2022-11-24V Viewed Control 3 2022-12-11 2022-12-11 ...
Blackdynomite's user avatar
0 votes
1 answer
145 views

When I run the command below, there is a syntax error highlighted at UNION on the last line. I am really not sure why. SELECT * FROM ( SELECT (final_exp.deploymentyear + number) ...
kestyoner's user avatar
5 votes
3 answers
907 views

I have a table tab1 in timescale db which has 3 columns tag, time, value. time and tag make up the pk for the table: (time, tag). There are more than 500 lakhs (50 000 000) of rows. I need to find the ...
CuriousCurie's user avatar
3 votes
2 answers
164 views

I need some help here, my request is : List the bookID and number of copy of this in Library (Number of copy in library = number of copy – number of copy student borrow but not return yet) and this is ...
Long Hoàng's user avatar
1 vote
2 answers
83 views

How do i perform a where action on a newly created field that is populated with the values of two fields? select upper(column_a + ' ' + column_b) as newly_created_field, some_other_field from ...
pithhelmet's user avatar
  • 2,312
1 vote
1 answer
644 views

I am dealing with a problem in Postgres, where I have table ORDERS with column RECEIVED_AT and table CURRENCY_RATES with column VALID_FROM. There are similar questions on StackOverflow, but ...
Robert Soroka's user avatar
0 votes
1 answer
586 views

with a as( SELECT '[{"residential" : 100}, {"childcare" : 200}, {"open space" : 50}]'::jsonb t ) select t->'childcare' from a this keeps returning null when it should ...
ziggy's user avatar
  • 1,558
1 vote
1 answer
120 views

A table of offers for different clients: PERIOD |CELLPHONE | IDENTIFICATION | FIRST_DATE | LAST_DATE | UPSELLING | IPHONE 202208 56961424344 152783337 09/08/2022 23/08/2022 1 ...
Lio Pecoraro's user avatar
1 vote
2 answers
547 views

Assume a table like this (in actuality I have 50 date columns to compare): ID MY_DATE_1 MY_DATE_2 MY_DATE 3 1 2022-10-1 2022-11-1 2022-12-1 2 2022-10-31 2022-11-31 2022-12-31 For each record, I want ...
redOctober13's user avatar
  • 4,066
0 votes
1 answer
502 views

We're having some logic to detect duplicate posts in out system. The query looks similar to this: select * from posts outer lateral join (select id from posts where id != outer.id and (tag = outer....
aldm's user avatar
  • 379
1 vote
1 answer
35 views

I got 6 tables: Albums id_album | title | id_band | year | Bands id_band | name |style | origin composers id_musician | id_song members id_musician | id_band | instrument musicians id_musician | ...
WebSurferPenguin's user avatar
0 votes
2 answers
222 views

I have one table (Bigquery), which has ', ' separated values in two columns: id tag_id tag_name 1 1, 2, 4 a, b, d 2 3 c 3 1, 4 a, d For each tag_id is 1:1 ...
Anita's user avatar
  • 285
1 vote
1 answer
31 views

You are given a database of notebooks that contains two tables. the table notebooks\brand contains data about the name of notebook brands. the table notebooks\notebook contains data about the name of ...
Maks's user avatar
  • 113
-1 votes
2 answers
55 views

I need to set up a query that will split up a single record into multiple records based on values from multiple columns in a single table. Right now, a current parcel record would read as: table....
Cbrown88's user avatar
1 vote
1 answer
342 views

thanks for your time! Basically, I'm trying to filter a NxM table using foreign keys, with 0,1 or N different tags. The problem is that LEFT LATERAL JOIN yields bizarre results. Please, don't mind the ...
Leonardo's user avatar
  • 3,201
0 votes
2 answers
527 views

I use SQL Server, and I created view and added new column which contain mathematical equation Let's say I have this: create view as select a.date, a.sale, a.buy, profit = a.sale -...
Khaled Nasser's user avatar

1
2 3 4 5