I have a query that returns the min, max, avg and total for two different products. The client however wants the min, max, avg and total combined for both products. However I have an undesired result …
PostgreSQL check number of tables that match regex
It there a good way to check the number of existing table in the database that matches a particular format? For example, I am looking for any table names that starts with ‘rangtable’, such as ‘…
nested join in Db2
Folks, what is wrong with this query i get error stating below in DB2 LUW. [42703][-206] “d.sales” is not valid in the context where it is used.. SQLCODE=-206, SQLSTATE=42703, DRIVER=4.23.42 [56098]…
MySQL – While Exists from a snippet throws error
I was reading through this page https://www.sqlteam.com/articles/more-trees-hierarchies-in-sql (great article on managing hierarchical data in SQL) and following along in MySQL and was trying to run …
How to record who edited a table in my sql
Is there a function to automatically update a column specifying who created a new record in a sql table? Something similar to the timestamp, but that instead of the time it shows the user who has …
Get query results for all date values besides current month
I need to get values for data excluding current month and taking this year into account. What I currently have is the following WHERE 1=1 AND CAST(created_at AS DATE) >= ‘2018-01-01’ AND …
Stored function not returning a table in SQL Server
I’m trying to create a stored function called func_GetMenuItemsForMenu. For this function, I need to pass the ID of the menu to it. The function will find all MenuItems that are on the menu. It will …
Using Column Alias as Values in other columns of table in Case statement
I have a sql table that has columns FundId, BreakdownName, BreakdownType and BreakdownValue FundId BreakdownName BreakdownType BreakdownValue F00000OCVS Cash Long 10.69 …
Multi Part Identifier Can Not be Bound
I’m having trouble getting past this error. I’m using SQL Server 2017 (v14): The multi-part identifier “PS_FFC.Date” could not be bound. The multi-part identifier “PS_FFC.Date: could not be bound. …
How to get maximum of Five consecutive values in an Year?
I have a yearly list of sales of an item for the past 20 years. the data is like this. date ; sales value 2001-01-01 ; 423 2001-01-02 ; 152 2001-01-03 ; 162 2001-01-04 ; …