Skip to content

SQL Select One Record over another based on column value

What I am trying to do is select rows based off of a ‘priority’. Say I have this: I want to choose one row each for the control ids (the whole row), which would be the third row, because there is no priority, and the 2nd row becuase it has priority. So if I have two control IDs that are

How to sum and pivot a table in SQL?

I have the following table: col_a col_b col_c 1 0 1 0 1 0 I want to sum up each column and assign a value to it based on the output, with the output like-so below: column sum string col_a 1 ‘string one’ col_b 1 ‘string two’ col_b 1 ‘string three’ I’ve tried the follow…

ERROR cursor does not exist after first loop in PL/pgSQL

I need to load a large number of csv files in to a PostgreSQL database. I have a table source_files which contains the file paths and a flag which indicates whether a file has already been loaded for all the csv files I need to load. I have written the following code which loads the first file correctly but t…

How to convert decimal values to time values in oracle?

I have a table that is formatted like this: I want the output to be like this: Basically transform the values in the dec_time field into time values like the example above in new_dec_time. This is my SQL so far: This simply changes replaces the decimal point with the semicolon but doesnt add the 0s where need…