Good day everyone. I have a table as below. Duration is the time from current state to next state. Timestamp State Duration(minutes) 10/9/2022 8:50:00 AM A 35 10/9/2022 9:25:00 AM B 10 10/9/2022 9:35:00 AM C … How do I split data at 9:00 AM of each day like below: Timestamp State Duration(minutes) 10/9/2022 8:50:00 AM A 10 10/9/2022 9:00:00
Tag: sql
Sum of quantity column based on the grouped of product_id column values with their respective names form name column
Here is what my table looks like: Here what I need: I tried this code Answer GROUP BY will do the trick in this case! Replace the column names with the ones from your database table.
Group by days of a month in CockroachDB
In CockroachDB, I want to have such this query on a specific month for its every day: the problem is that I want it on my local date. What should I do? My goal is: “month, day, count, sum” as result columns for a month. UPDATE: I have found a suitable query for this purpose: Thanks to @histocrat for easier
Is such a result possible with a query from an SQL database?
I want to fire a query to get such a result: Tables Schema I guess it’s not possible like that? I don’t have any experience with text-based databases, but I can well imagine that this can be achieved with a MongoDB. Because ultimately I want to have a js object at the end of the day. Answer Here’s an example
Calculating Value Count and Percentage
I have a table Currently Enrolled The table is basically to get an idea of how many supporters, undecided, and opposition they were. Then once I get the count I wanted to then do another calculation to find out what that percentage was. Essentially what I want to be able to do is: Count the total number of supporters: SELECT
Can I start the quarter of the year from the month I wanted to on PostgreSQL?
I am using PostgreSQL 14.5 I can classify the year by quarter using the Postgres keyword QUARTER as illustrated in the documentation just like SELECT EXTRACT(QUARTER FROM TIMESTAMP ‘2001-02-16 20:38:40’);. And it works. The default quarter starts with January. Which makes complete sense. I.e, quarter one is composed of January, February, and March. The others follow then. But, I wanted
SQL : instead of using a union want to use a where clause but one of the clauses is only true if another clause is true
I would like to not use a union in my SQL query – how can I rewrite the following query? How can I rewrite this without the union? Answer Use Boolean logic: If you are combining with other conditions then make sure you have the correct parentheses to make it evaluate properly, e.g.: … so you aren’t caught out by
How to assign integer values to based on id in SQL Server
I have a table like this: id value 15 a 15 b 18 c 19 d 20 e 20 f I want to create a select query with replaces the id value with integers starting from 1. id value 1 a 1 b 2 c 3 d 4 e 4 f This is my expectation. I am using SQL Server
What can I use instead of “Set Identity Insert On”?
I have stored procedure in SQL Server. In this procedure, I delete duplicate records and insert one unique records to table. When I insert new unique record I am using below script. Everthing is okey with this script but in the production SET IDENTITY_INSERT command needs to ALTER permission. Giving this permission should be dangerous so I can’t give this
How do I select unique values in a single column with multiple column selected?
the query is actually fine and running but it doesn’t select distinct the column A.CONTRACT_NUMBER. This is the code: It runs normally but after checking the data, there are still repeated values in the A.CONTRACT_NUMBER column. A.CONTRACT_NUMBER is like the primary key column and I’d like to select unique values to that column Thanks! 😀 Answer Per contract you want