Skip to content
Advertisement

Category: Questions

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 following SQL: This gives me three

Laravel/MariaDB: errno 150 “Foreign key constraint is incorrectly formed”

I’m on Laravel 5.4, PHP 5.6, Ubuntu 18.04, MariaDB 10.4.8. When I run php artisan migrate, I get: I’m trying to use https://github.com/klisl/laravel-comments. Before trying to perform a migration with this package I had created DB at phpMyAdmin, had configured .env by adding DB name and stuff, had successfully run php artisan migrate, php artisan make:auth and php artisan make:controller

Using SQL, when there are multiple columns with dates. how can I determine and return a row where the date is between the other rows?

I am building a table for a data warehouse that needs to have a row for each change that occurs. The issue is that there are sometimes changes that occur in the subgroups and I can’t figure out how to show those changes. For example, I have the following table: RowNumber Code CorrectedProductYear ProductYear Product CategoryYear Category PartYear Parts KeepRow

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 then

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 needed. Is there a

Advertisement