I am trying to obtain row for a query.. where row value1, value2 in minimum end_date is equal to the max end_date, per group of id’s. My current query only obtains the row value1, value2 from the max end_date in the query result: This result obtains the most recent record, but I’m looking to obtain the row where value1 &
Tag: postgresql
Execute same query multiple times with different parameter postgressql
I don’t know how to easily explain what i need to do but i’ll try. Lets say i have a user table with 5 users. instead of just do a select * from users i need to do this different and more difficult. I need to build a query that for each row in users table runs a query with
SQL how to select distinct several columns
lets say there are several columns (c1, c2, c3, c4) It’s okay for each column to be appeared several times, but I want to select all the columns with several columns distinct. I want SELECT c1, DISTINCT(c2, c3), c4 something like this but it doesnt work, and GROUP BY doesnt work as well. somebody help me please Answer You simply
postgres column allow space to column while making alias name
python code to make query from postgres table error: I wants to add space to alias name of column thats why i have written my code like this. Plese check how can i fix it. Answer Postgres follows the SQL standard and uses double quotes, not backticks, to escape database object names (such as column or table names). Use this
Full outer join not giving the answer I need
I am using PostgreSQL and am having difficulty with getting a series of queries that combine the data from two tables (t1, t2) t1 is studyida gender age a M 1 a M 2 a M 3 b F 4 b F 5 b F 6 c M 13 c M 14 c M 15 and t2 is studyida studyidb
How do I make an SQL query in Postgres that finds total balance and applies credit fees for the year?
I am totally new to Postgres and I cant find any example of what I am trying to do… I have a table of transactions for a year: amount | date Positive transactions for incoming money. Negative transactions for credit payments. And I need to return a total for the year that also reflects charging a $20 fee for every
How to overload the equality operator for primitive types (int, real…)?
Is it possible to overload the existing equality operator in PostgreSQL to give a new definition of equality between two values of type int or real? I think it’s against the rules of overloading but I wonder if there’s a way to do it anyway. I tried this: But when I use the equality operator in a query I don’t
When do Postgres transactions fail?
I was wondering at what point a transaction actually fails in Postgres. By this I mean stop working, and return an error. Is it after the first failed query? Does it try all queries and then return failure? Hopefully it fails fast on first failed query, but I don’t know for sure. For instance, if I have a transaction with
How to grab the ID of an artist so i can insert the album into the database with the artist’s ID?
Here is my schema: This is what I’m doing: Right now I’m inserting into albums by looking at the table for the artist ID and typing manually. How can I do this automatically? My application will receive the song title, artist name and album name. So it will need to look for the artist ID if the artist exists and
How to make a join with the same table to insert the maximum column value?
I have a table that keeps activity records, containing the date of registration and other information about the activity performed. I would like to make a query that would return one more column in the table, containing the maximum record date. I don’t think it’s too complicated, but my knowledge is limited on the subject. Would a join between tables