Skip to content
Advertisement

Tag: postgresql

Get rows within current month

Get the rows from a table filtered by current month in psql. Example table – After query result, assuming current month is July, 2020: Answer The usual approach is to use a range query to allow for an index usage on registration_date

additional condition in a SQL query with min(Date)

I have the code presented below provided to me by one of the members but I do not understand how it acts: The code extracts the min of start from another table. I wanna add an aditional condition like: I cannot insert the condition without an error. Also, I need only to see min(pr.”AsigStart”) from the pr table not all

Double quotes problems with Postgres

I am using Django with postgres. Here’s the snippet of my code which I am using to create tables in the db. My question is: why is the user table getting renamed as “user” (with quotes) why is the role_id getting named as role_id_id where as I have clearly mentioned role_id to be my column name? Answer After reading few

Group rows on condition PostgreSQL

I have a table with repeated Column1 and Column2 pairs, let’s say this is ‘many-to-many’ table. Also, I have there one extra integer column – Column3. What I want is select conditionally grouped rows, like 1). If pair of Column1 and Column2 have several records contains 5 value among others – then it should be grouped into one row with

SQL – concatenate values in columns but keep only first non-null value

I have the following table in Postgresql. The first 4 records are the base data and the others were generated with the ROLLUP function. I want to add a column “grp_1” that will display the first non-null value of the columns grp1_l1, grp2_l2 and grp2_l3 I can get to the desired result by nesting 3 “case” functions using the SQL

Advertisement