Skip to content
Advertisement

Tag: tsql

Cumulative sum of a column

I have a table that has the below data. I wrote a query that will calculate the sum of cumulative rows and got the below output . Now I want to to filter the data and take only where the POOL <=300, if the POOL field does not have the value 300 then I should take the first value after

Get the count of records from another table

I have a view that looks like this: which is defined using this SQL statement: Now I want to count the records for another table (TABLE 2) based on the C_CODE, P_CODE and PH_CODE and display it as a column TOTAL in my view. How can I do this? Answer one way is to use subquery:

SUM with Multiple Conditions

I’m writing a query on SQL Server and have hit a wall on cumulative sum with multiple conditions. I need to sum all the purchases in a day made by a user, I can do it separately, sum purchases by day(Daily_Total), or sum purchases by user(User_Total), but I run into a wall when I need both conditions met(User_Daily_Total). I tried

Group data in intervals

I need to group data in intervals of 15 (or X) minutes in sql. For example, i have the next scenario. The result that i expect to obtain is I tried using Lag function but i dont get what i want, because it add interval to each row and continues grouping. Thanks in advance and apologies for my bad english.

Trying to update Date Format from (DD-MM-YYYY) to (MM-YYYY) SQL

I’m trying to update my date column which is (eg. 2012-04-20) format in into mm-yyyy. I searched for solutions that you can do by converting to varchar however it gave me an error Msg 241, Level 16, State 1, Line 4 Conversion failed when converting date and/or time from character string. This is the code I’m executing Any idea how

SQL Select One Record over another based on column value

What I am trying to do is select rows based off of a ‘priority’. Say I have this: I want to choose one row each for the control ids (the whole row), which would be the third row, because there is no priority, and the 2nd row becuase it has priority. So if I have two control IDs that are

Advertisement