I have a table like below in SQL server Date Store ID Sales Amount 01-01-2021 1001 1000$ 01-01-2021 1002 1000$ 01-01-2021 1003 0$ 02-01-2021 1001 1000$ 02-01-2021 1002 1000$ 02-01-2021 1003 1000$ 03-01-2021 1001 1000$ 03-01-2021 1002 1000$ 03-01-2021 1003 1000$ how to calculate count of previous days if Sales…
sum of value based on a category
I want to print the total sum of categories in every row using my-SQL and I am not able to do it can anyone please help me, example: store region sales 106 Atlanta 250000 107 Atlanta 300000 108 …
Select column names based on max value by row
I need select column name based on max value by row. I have snowflake database table: id cars_cat1 cars_cat2 cars_cat_3 a01 5 2 8 a02 6 1 5 a03 …
How to get previous month from ‘yyyy-MM’ date format in Hive
I want to get previous month from ‘yyyy-MM’ format value in Hive. I tried with ‘add_months’ but couldn’t able to get. select add_months(‘2021-06’, -1) Eg: I have one string column having value ‘2021-…
Insert repeating tag xml data to multiple sql table columns
I’m having following XML and query. header tags are there and Item tag can be repeated up to 10 tags. I want to insert those item no and qty in separate columns. Here I mentioned only 2 tags for Item but in real situation there are 5 tags in XML. So in worst case scenario it will be 50 columns.
Select average entries per day into table
Ok I have looked at multiple entries in stackoverflow for this but cant seem to quite work them for me. I have a table called email_Archive It contains every email sent by every user. Columns in Db are: Challenge: I am trying to get the average amount of emails sent by a select list of users per day for the
HANA: How to add a unique contraint on a column that is already indexed?
Having the following schema: I am trying to a unique contraint to the column. But this runs into an error: I can understand that the column is already indexed because I have created the index by myself. But I want the column to be unique. Is there a way to do this? Answer This is indeed an undocumented limita…
Divide by zero exception in SQL Server
I have an update statement which has division operation and one row throws exception Divide by zero exception and I see that none of the rows got updated . How to continue on exception so that rows which doesn’t encounter 0 gets updated and row which has 0 fails? Its just a normal update statement witho…
Count(*) of two sql statements where results are subset of another one
I have a table which has ~500 GBs of data and have two queries running on it. I feel Query 2 execution on whole table is un-necessary as the results are subset of Query 1. Is there any optimized way to first execute Query 1 then run Query 2 on the results of it and finally return Count of both
Unable to Run Update Query in SQL Azure *Invalid object name ‘DataSync.provision_marker_dss’.*
I was syncing my Azure SQL Database with On-Premises SQL Database which created a lot of tables in the Online database (As Usual). Anyway, It was working fine. Now, I had to re-create the Azure SQL Database. So, I deleted the Sync Group & Sync Agent as well. Everything’s working absolutely fine unle…