I have the following table, My goal is to create a supervisor view in which there is a 4th column that has the name of the supervisor that matches the S code. My query returns to me either nothing except the column headers or a never ending recursion that loops into the 100,000’s. What I’ve writte…
Tag: sql
SQL – How to select date from the past 5 years to include 1st of Jan of the oldest year
I am trying to select data entered for the past 5 years (to start from the 1st of Jan of the first or oldest year). I’ve constructed the query below but it does not begin from the 1st of January of the oldest year. Any help would be appreciated. Answer You seem to be using MySQL. The simplest method is
Tag a row based on aggregate value condition
Here is my dataset, where order is the fix sequence of each product. What I want is another column in here, lets say TagID. TagID is an int value that will based on the aggregate Count column, group it by product if it is greater or equal to 5. So the dataset would look like this: How can I accomplish
Can’t figure out how to get duplicate values out of table in SQL redshift
I am trying to return the foretasted value per item, per warehouse, per day and then add them up for the week. I am pulling from two tables depending on the demand date, but the issue is that both tables have a “creation_date” column with timestamps, so it’s creating multiple raw_forecast en…
How to create a view using data from two tables
I have two tables ITEM id (int), model (varchar), weight (float), fk_type (int) TYPE id (int), name (varchar) And I want to create a view with TypeName (for every type name) –> varchar NumberOfItems (total number of ITEMS for TypeName) —> int NumberOfModels (total number of MODELS for TypeNa…
Sort records with an associated field
I want to order records with associated records in GORM V2. I have two structs: type Client struct { gorm.Model UUID uuid.UUID `gorm:”type:uuid”` ClientProfile …
Get Current date, current month, current year depending on user selection – SQL stored procedure
I have a stored procedure that gives results depending on multiple values from the User(filtering), in my query I have 2 date columns date_start and date_end, I want to allow the user to return data depending on his selection from 2dropdownmenu one for start date and the other for end date as this: (this day …
SQL query to combine the results from two tables
I have these two tables and I want to build a SQL query: My search criteria is: Name (in field Brother and field Speaker) Congregation (in field Congregation in both tables) I want the resulting view to be a single list of all records, sorted by date (fields Talk Date and Last Given). So: Away Talks I am inte…
How to automatically create a comment on CREATE in Postgres?
I would like to create a trigger which gets fired once a table is created in a schema. This trigger should add a comment to the newly created table, something like: With add_comment doing somthibg like: However, it seems I can only add triggers on table level. How could I achieve to add comments to newly crea…
Problem using create view and explain plan
I want to test the efficiency of this query using explain plan for. The query works without the explain plan but when I use it I get this errors: I used explain plan on queries without create view and they worked. I don’t know what is causing the error I have tried changing the parenthesis but I get the…