I have a table of events that span over several years. title start_year end_year Event 1 1976 1983 Event 2 1977 2002 Event 3 2018 2019 Event 4 2003 2019 …
Percentage of existence in a group in SQL
Hi I have a requirement of finding the occurrence percentage of specific items in a group. My table is like this Team Objective Status ——————————– Team1 Obj1 …
How can I replace a `’` in a string in SQL?
I have to replace special characters in SQL. My problem is with ‘, because it is used for start and end of string in SQL. I tried: ID = REPLACE(ID, ”’, ”) ID = REPLACE(ID, “‘”, “”) But both not …
How to query MYSQL table to get counts of column occurrence overall and within past year?
I am using MySQL and want to create a query that will count how many times appointments happened per contact_id within the last year, last year, and how many times the occurrence happened overall. …
How to look for missing rows within a group?
Consider the data below. I am trying to find situations where in a specific RequestID, there is an Attempt: 0, but Attempt: 2 is missing. I’ve tried looking for Attempt: 0 with a WHERE predicate …
How to search/select a list of composite index values and get the exact matching rows in SQL Server?
I have a list of value pairs that I have to search in a table in SQL Server. the table is something like this: | id | class | value | | 1 | A | 300 | | 2 | A | 400 | | 1 | B | 500 …
Is there a way to turn the results of a SELECT, FROM, GROUPBY statement into a new table?
Basically I need to put some tables from SQL into Excel to analyze it with a third-party program. However, when using Excel, the PivotTable date columns are in a specific format (d mm) and for the …
Converting WHILE to CROSS APPLY
I have a scalar function which I am converting to TVF. In the scalar function I have the below while statement: WHILE @ReviewDueDate < getdate() SET @ReviewDueDate = DATEADD(DAY, 30, @…
MySQL Grouping using group_concat and then Group BY
I have a table like this: Basically, I want to group all names and give the count of such groupings like: Since there are 2 users with cooking and cleaning, 1 for washing and 4 for cooking. I am …
UPDATE column based on whether it has NULL in a grouping
This might be very simple question, but I just can’t come up with a solution. Here is an example create table #Example ( Key1 varchar(55) PRIMARY KEY, Key2 varchar(55), Key3 varchar(…