Hello people of the internet. Once again I seek your advice. I have multiple meter readers collecting power consumption every 5 minutes and storing to MS SQL Database. I execute SQL query to get a days worth of data from all meter readers and check how much power it has used every five minutes and returning as ‘ Consumed ‘
Tag: tsql
Finding cumulative sum using SQL Server with ORDER BY
Trying to calculate a cumulative sum up to a given number. Need to order by 2 columns : Delivery, Date. Query: Results: Expected results: Version: Microsoft SQL Server 2017 Answer You need a third column in the ORDER BY clause to break the ties on Contract_Date and Delivery. It is not obvious which one you would use. Here is one
Replace row with Column Data in Sql Server
I have a table with some data and I was trying to Replace the Column with Row. The above Query gives me the result in one single row data. But I want the Result in below format I have tried the Pivot Operator using Derived Column but got confused during implementation. Please help to get the correct query. Answer Assuming
SQL Key Value Pair Query
I have two tables: Product Table ID (PK), Description, CategoryID, SegmentID, TypeID, SubTypeID, etc. Attribute Table ID (PK), ProductID (FK), Key, Value And I would like to query these two …
SQL how to get latest date and update every time it occurs (not using MAX)
I’m trying to get the latest date of starting event before it occurs again. Data I have: What I want to make: I want to create another column with the latest start time and record it, then update it whenever it happens, and keep that value from there until start appears again. What I tried: This didn’t work since MAX
Making groups of dates in SQL Server
I have a table contains ids and dates, I want to groups of dates for each id id date —————— 1 2019-01-01 2 2019-01-01 1 2019-01-02 2 2019-01-02 2 …
Why is my calculating a percentage not working correctly when I am dividing?
I am trying to see what percentage of customers paying LL and the percentage of customers that are paying LP. For example I have 1 customer in LL and 1 in LP so percentage should be 50% in Cust_LL_Pct …
Extracting Dates based on Months
I have a table in an MSSQL database that lists when students start a programme. The academic year runs from August to July. Where a student starts on 01 Sep 2019 I want to show that they started in …
SQL select row with max value or distinct value and sum all
I have the following data that is returned to me. I need to get a distinct or max sum of all the commission by taxid for a single repnbr. The ‘qtrlycommrep’ column is the value I’m trying to get to, …
Converting month name to month number in SQL Server
I have a column (says Period_name ) that accepts varchar value. Inside the column, I have inputs likeJan-19, Feb-19, etc. I need an SQL instruction whenever left of Period_name comes like Jan, Feb then it should convert into corresponding month number. For example Input Output The SQL query condition is as follows: Thanks 🙂 Answer Just another option is to