My data source looks like below. And I want output like below. Basically, it should list each Employee multiple times for each date between those periods. For quick and easy, below is the Temp Data code. Answer Build a calendar table and join that.
MySQL error: Cannot add foreign key constraint (PrestaShop module)
I’m trying to write MySQL queries for my custom PrestaShop module. I encountered an issue while adding foreign keys and have no idea what might be wrong. I double checked column types and their existance. Here’s the error: Cannot add foreign key constraint And here is all the code I’m trying…
Oracle APEX master detail page creation: ORA-06531 error
I am creating a flock management application with APEX with the following PL/SQL scheme: In this scheme, the SALE and EVENT tables reference the EID field of the SHEEP table (unique identifier of 5 numbers and one letter – representing the yellow tag they have in their ears). I am trying to create a Mas…
Get values “0” and “1” alternated rows on SQL
I’m using SQL Server 2015, I have a table with a list of values “name”, my necessity is to add a column that alternate values “0” and “1” when the “name” columns changes. This is important for me because, I import this query on excel, and I will format the…
How to declare a cursor inside another cursor
How declare another cursor inside cursor c_employees? Note: cursor c_employees return employees_id and this id pass to other cursor in the where clause. For example Answer Cursors can take parameters hence But generally, when you start seeing cursors with cursors etc etc…its also time to look at whether…
postgres syntax error on grant select on table
I have a query: But on running this: I get the following syntax error: without grant query its working fine. What am I missing here? Answer To specify the schema, use ON public.abc. The syntax IN SCHEMA public can only be used with ON ALL TABLES. Also, you have to separate CREATE TABLE and GRANT with a semico…
Return records of one value and not in other values
Apologies for asking such simple question but here I am getting trouble while getting records from single table, my table contains records which have different values in prod_code for similar product_number. I want records of such product_number which have specific prod_code, and not others. For example from …
MYSQL: Can’t update table in stored function/trigger
I have a table called “report” I am trying to create a trigger for in case insert a state with value “failed” for the ip_element “10.66.16.55” and path “/dev/map/4-4”, the state change to “ok” I get the next error: Answer You cannot update the table …
How to output total number of professions in SQL based on 4 tables
I have the following tables available through this link: tables. I’m trying to do a query where I list out the degrees (profession) and the counts associated with that profession. If the degree is listed more than twice, it should output ‘Popular Degree’. I coded: I get an output of this, wh…
How I fetch values from one column based on distinct values from other column?
I have two columns in a table and I want a query to fetch First column values based on distinct values from Second column. Since, There are multiple combinations of First and second column I would like to have the first match from each combination. DATASET: First Column Second Column A abc B abc C abc D abc F…