I have below table structure in SQL Server: Is there a way to group above data into one hour interval instead of 15 minute interval? It has to be based on start and end columns. Thanks, Answer Maybe something like the following using datepart?
Tag: sql
SQL Server: Convert YYYYMMDD-HHMM and YYYYMMDD to mm/dd/yyyy hh:mm
I am trying to convert the time format from YYYYMMDD-HHMM and YYYYMMDD to mm/dd/yyyy hh:mm. My issue is that the data is not consistent. Below is some exemple: I tried to use: but the issue is that some data does not have time. Answer You can do it like this:
Add new column with Boolean in PL/SQL
I’m learning PL/SQL right now and I have a doubt. I have created the following table called tbProducts: And I have inserted some values so the table is like this: Now what I’m looking for is a boolean variable that can be called bUpdate that returns FALSE if today’s date (26-AUG-2021) is gre…
Postgres transpose a row
I have a table which looks like the following :- I want to transpose it to the following form, in Postgres: I know I’m supposed to use the pivot operation to do this, but I can’t figure out the right syntax to get this done. Any help to get this done will be appreciated. Answer That would simply b…
SQL Summing columns based on date key
I have a dataset as given in the link, DataSet I want to segregate the column “order_item_unit_status” as separate column and bring respective transaction amount for the same. Desired output is given below. Objective is to consolidate the txn_amt into respective categories and group them based on …
Combine like rows based on substring of one column?
I have a table of parts that looks like this: Part Part Num Thing1 Thing2 Thing3 Thing4 Door 10105322 abc abc Door 10105323 abc abc Door 10105324 abc abc Door 84625111 abc abc abc Door 84625118 abc abc abc Door 84625185 abc abc abc Door 56897101 abc abc The part number is always 8 characters. For many parts, …
How to use pg_dump correctly in order to do a database migration?
Hey everyone I am fairly new to doing a pg_dump in Postgre sql. I have logged into the server and am running as postgres user. I try to run the pg_dump in order to do a database migration but I keep getting a “Permission Denied” prompt. I believe that I have the highest permissions and should be a…
Having weird exception using MAX(CASE WHEN) in query: DB2.iSeries.iDB2DCFunctionErrorException: ‘An unexpected exception occurred
I have the following query to put some data from rows in columns: But when I try to run it in the following code: I get this exception: “IBM.Data.DB2.iSeries.iDB2DCFunctionErrorException: ‘An unexpected exception occurred. Type: System.AccessViolationException, Message: Attempted to read or write …
Grafana change SQL query for a totalization of each data point
I have a grafana dashboard that charts a bunch of data on 2 query’s, this is one below: And this is the other query: Would anyone know how I could modify this into one SQL expression for a totalization? Instead of 50 different lines on my chart, just one line of all variables added together. The data is…
Change + ordered to + leading
I’m trying try to find the most selective criteria to start joining in SQL. I tried this: But this + ordered is deprecated. How I can implement this query using + leading? Answer Use the leading hint and put the table aliases between parentheses in the order you want the database to join them, for examp…