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
Category: Questions
ORA-04091 TABLE ODB.EMPLOYEE IS MUTATING, TRIGGER/FUNCTION MAY NOT SEE IT. IS THERE SOMETHING WRONG WITH MY TRIGGER?
Trying to create a trigger when there is an update of Status on Employee Table and capture some values for the record in Employee table and Employee_Header table for that record and send an email. The trigger throws an error. Answer You can’t select from a table which is just being changed; it is mutating. Though, as you can use
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
Select 2 products per city with most counts in PostgreSQL
I have this dataset: I want the top 2 counts per the_city, so the expected result should be: I have tried this but it’s wrong Answer It’s greatest-n-per-group problem. You can use row_number()over() window function to to serialized city wise product list in descending order of count(*). Then select first two rows from each city. Query: Output: the_city the_product product_count
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
Query to select all tables with specific last column Ibm Db2 z/os
Goal: I need to create a query to select all tables with specific last column Ibm Db2 z/os So I know I need to change my where clause for this but pretty much I want to select all the tables in my schema that have the last column as BATCH_ID. I’ve tried a length based where clause but can’t figure
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
In SQL how to find data rows separated within few seconds of each other
I have a table in which sensor events are recorded. And a random log is selected for testing every hour at a random time. I want to find N events which are within T seconds of each hourly picking. Data looks like this Event 1 and 3 both happened within 4 seconds of each other. I want to find all
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