I have a table MF_NAVs which holds daily NAVs of mutual funds. I want to calculate the absolute returns over 1 day, 7 day, 15 days, 1 month, 3 month, 6 month, 1 year, 3 year, 5 year & since …
Tag: sql
Using multiple nested OR statements in WHERE clause makes query return incorrect results
I have a WHERE clause that has a nested OR statement, as seen here: The @NeedsFollowUp, @NeedsInitialVacc, and @NeedsTraining variables are all set by the variables above. When one or more of these are set to “1”, the query should return employee entries that match the criteria inside their relate…
Loop to create new columns
Say that I have a SQL Server table which has 4 columns MonthEnd, Gender, Weight and Age. Now, the MonthEnd go from 201901 through 201912. I have a process where a run a query which generates a variety of metrics, for instance sum(Weight) and average(Age) for each month. Right now, I set a where MonthEnd = 201…
Replace a recurring word and the character before it
I am using SQL Server trying to replace each recurring “[BACKSPACE]” in a string and the character that came before the word [BACKSPACE] to mimic what a backspace would do. Here is my current string: “This is a string that I would like to d[BACKSPACE]correct and see if I could make it %[BACK…
SQL some selections into one (or get two colums from one)
I use PostgreSql, I have two tables (for example) Let table1 will contain stores, there are 2 types ‘candy store’ and ‘dental store’. Each row contains information about a customer’s purchase in a …
how can i find unique conversation from table in sql
I Have this table: [Messages table] I need to find the number of uniqe conversation – conversation is define as senderid sent msg to reciverid, and reciverid has replied (no matter how many times or …
Inserting a generate_series select date statement into an array column
I have a Postgres table with a schema that looks like this – Table “public.nav_due_dates” Column | Type | Collation | Nullable | …
how to select rows with no null values (in any column) in SQL?
I have a table called table1 It has 100 columns: {col1, col2, …,col100} I understand how to SELECT rows not containing null values in a specific column for instance col1: How do I SELECT all rows that do not contain null values in any column Attempt but this returns an error in MySQL (which I am using) …
how to drop multiple functions in Oracle
I want to drop multiple functions from my database at a time in Oracle’s SQL developer. Is anyone has an idea how to create a script for that? Answer Well, the static option to drop the functions (sometimes considered more secure as you can double-check what you are removing) consist of two steps 1 R…
SQL how to find the product group with highest porportion of expensive items
I have a table with products, product_group and price level. How can I find the product group with the highest porportion of expensive items? I have tried this query, but it keeps all price_levels, not just the expensive ones. Essentially, I want to divide the number of expensive items in one product group by…