I have a table with two columns wind_speed and wind_direction. I want to have a custom aggregrate function that would return average wind_speed and wind_direction. wind_speed and wind_direction in …
Tag: postgresql
SQL Join : how to show the first table data even the 2nd table condition false
I want to keep show my first table data even the second table condition is false. Table 1 ————————— ID | Name ————————— 1 | Panda 2 | Tiger ————…
Postgres SQL select query syntax
I have this SQL statement, I am getting a syntax error: SELECT * FROM user_table INNER JOIN ( klass_table LEFT JOIN room_table ) Syntax error is vague, it says: You have an error …
What’s the best way to count the number of references based on conditions in both “home” and “away” tables?
I’m working on a project, and using Knex for it, (though if you give me raw SQL I’m pretty sure I can convert that as well.) So, here’s the sitch. I have tables ‘group’ and ‘user_group’. table ‘…
Postgresql: Unique constraint over Union of 2 columns
I have the following tables: TRANSACTIONS id | amount —————— 1 | 100 2 | -100 3 | 250 4 | -250 TRANSACTION_LINKS id | send_tx | receive_tx ————…
What is the best way to compare a name field with a string value?
I have a query that compares a string value against a name field in my database. The structure of the name field in the DB is not consistent, it could be any of these: John Doe Doe John Doe, John My …
Database Query to generate a Time-based Chart
I have a logins table in the following (simplified) structure: Now I want to generate chart like this: https://prnt.sc/mifz6y Basically I want to show the logins within the past 48 hours. My current query: This works as long as there are entries for every hour. However, if in some hour there were no logins, t…
SQL refer Primary Key in same Table and Query
I am maintaining a table of Items (Id is Primary Key). Some Items have Parent Item ( Which is also an Item, the colum Parent holds the Id of the parent Item, which is also in the same table. Some …
Count as duplicates similar values
I have following tables: Orders order_id 9 10 11 Order_details order_id, product_id 9, 7 10, 5 10, 6 11, 6 11, …
Find most recent row per user and day in sql query
I want to find the most recent purchase per customer for each date (a customer might make multiple purchases on a given date and I want the most recent for that date). My dataframe looks something …