NOTE: Just a practice problem.. NOT looking for free homework answers. The practice problem I have asks to report the number of flights by plane’s year in ascending order of plane’s year. This requires the joining of two tables, the flights table and planes table. I believe the SQL should be relatively simple…
Tag: sql
Multithreading to load data to SQL tables?
On a weekly basis, I run a Python script that migrates data from a PostgreSQL server to a Teradata server. One table at a time, this script: DROP/CREATEs the Teradata version of the table, pulls the new data from PostgreSQL, saves a copy of the table data as a CSV in a network drive (for business reasons), ad…
How can I unite these two related queries?
I have this query to check if a person is a customer or have been: And I have this other query to get the locations: How can I unite them and show person location as a single row on the first query? Answer If I follow this correctly, you can use lateral joins: As commented already, your original first query
SQL: Select certain rows with window functions in MySQL/MariaDB
My problem can be simplified to the following example: Now I’m looking for an sql statement which selects all rows (ordered by dfrom) having a dfrom not between the dfrom and dto of any previously selected row, possibly using window functions to get informations on other rows, like this: resulting in: C…
SELECT NOT IN with multiple columns in subquery
Regarding the statement below, sltrxid can exist as both ardoccrid and ardocdbid. I’m wanting to know how to include both in the NOT IN subquery. Answer I would recommend not exists: Note that I changed the table aliases to things that are more meaningful. I would strongly recommend prefixing the column…
How can I create a column which computes only the change of other column on redshift?
I have this dataset: The dataset has the product the company sells and the customers who saw the product. A customer can see more than one product, but the combination product + customer doesn’t have any repetition. I want to get how many people bought the product before the customer sees it. This would…
is there any way to insert an array values into INT datatype in SQL?
I am trying to insert into a table called Observations, I need to insert 10 rows using for loop, I have an array of 10 values that need to be inserted in a column called sens_value which is an INT type. I have tried the following code but it cant take sensValues[i] as an INT. I am using noodjs to
How to set pdo timezone at connection
I have this code where I connect to database and the code is working properly. However the now() function of MySQL is out of sync with PHP set default time zone function. I am comparing the PHP date with MySQL now. Therefore, I wanted to set the database time zone as well. I wanted to set the database time up…
Way to suppress PostgreSQL-Error with custom error
For the last hours I got stuck on the problem, that I want a custom error (“Wrong airline_id. Please check your input again”) over the normal error code (insert or update on table “flightplan” violates foreign key constraint “fk_flightplan_airline”). But no matter what I tr…
Querying specific relation that doesnt have a value on a column
I have the following tables: Person (id, name, address) Person_subscription (id, person_id, status) Does a person have many subscriptions but no active one? get that person as ‘Ex-Customer’ Does a …