Skip to content

Tag: sql-server

how to use GROUP BY based on 2 specific columns

I have a table in SQL Server which looks like this : each ticket id can have multiple order issue. On each row I need to calculate ticket full revenue as below : SUM(revenue) of all items within the same ticket id So in my case, ticket id has 3 items (10,20,30) so the ticket full revenue = 30+5+15 =

Increase the value of a column

I want create a CTE or something that subtract a know value from a sum() of value. How can I solve this, I tried to use LAG() on my CTE but it faulted when my value is negative. This is what I tried to do: This is the result of the query And this is what I expect from the

How to check if an int contains another one as part of it?

The question is fairly clear. I wanna check if for example a number x is contained in another number y. And I wanna do it in SQL (also in LINQ if possible). Additionally those integer values(y values) are Ids from a table. So when LINQ is concerned, I am not looking for some general solution like: Examples: A…

Remove Duplicate Time Zones From SELECT query

I need help removing duplicate time zone records from my select query without deleting them. The current result is as follows: The table returns duplicate GMT start times for the same employee, the database appears to be duplicating the results based on different time zones. I just want to remove the duplicat…

Group by using linked tables

I have linked tables. Calls and Call Lines, both tables have a seperate ‘Call Type’ field, I am trying to get the number of calls and the number of call lines which were added on a certain date and then see the split for the types. The below query returns the number for each Call Line which was ad…