All Questions
Tagged with sql-server-2014 group-by
41 questions
2
votes
2
answers
113
views
GROUP BY works but I don't think it should
From https://learn.microsoft.com/en-us/sql/t-sql/queries/select-group-by-transact-sql?view=sql-server-ver16 it says "However, each table or view column in any nonaggregate expression in the list ...
1
vote
1
answer
76
views
Group by MIN value in SQL Server pivot table query
I have looked through some similar questions but still can't figure this out.
My query:
SELECT *
FROM
(SELECT
Sites.ID AS SiteID,
MIN(DateInspectionDue) AS DateDue,
...
0
votes
3
answers
101
views
How use select * with group by subquery in sql server
I have table of employees salary details records with columns
Id Name Year Month Salary
1 ABC 2021 Jan 50000
2 PQR 2021 Jan 40000
3 KLM 2021 ...
1
vote
1
answer
68
views
How to group by in FOR XML clause in SQL Server 2014?
I have this schema in fiddle
My code:
SELECT
MUID, weekcounter,
STUFF((SELECT ',' + Category
FROM tb EE
WHERE EE.MUID = E.MUID AND Ranknum <= 3
FOR XML ...
0
votes
2
answers
61
views
Grouping values in Group By clause
Please consider this simple table:
declare @tbl Table
(
Id int IDENTITY(1,1),
[Year] int,
[Month] tinyint,
[Value] int
);
insert into @tbl VALUES
(2010, 1, ...
1
vote
1
answer
67
views
List rows by count when some rows refer to another row
I'm attempting to write a query that will list items from Table 2 in order of how many rows reference it in Table 1. The difficulty is that some rows in Table 2 are actually based on another row in ...
0
votes
1
answer
74
views
TSQL combine two count queries with slightly different where clause into one output
I would like to combine the two TSQL queries below into one query.
-------------------------------------
USE [ourDB]
-------------------------------------
Select --
id
, count(id) as ...
0
votes
1
answer
65
views
Query row where column condition = 'x' only after a certain corresponding column condition = 'y' in SQL Server
apologies in advance if I'm missing critical information, I'm very new to this.
I have a massive database of devices, receivers, and corresponding value that counts up one as messages are received.
...
0
votes
1
answer
144
views
How to Join tables in SQL with SUM Function and Group?
I'm creating a report to display project wise cost and revenue. I need to group sum of A/P invoices and Sum of A/R invoices according to the project.
Same project could have many A/P invoices and A/...
0
votes
1
answer
61
views
Creating one record for a continuous sequnce of dates to a new table
We have a table in Microsoft SQL Server 2014 as shown below which has Id, LogId, AccountId, StateCode, Number and LastSentDate column.
Our goal was to move the data to a new table. When we move it we ...
-1
votes
1
answer
101
views
T-SQL -- find rows with one column value that are associated with multiple value occurrences of another column
T-SQL -- find rows with one column value that are associated with multiple value occurrences of another column.
The goal is to find occurrences of table1.col1 values that have multiple values for ...
0
votes
1
answer
23
views
How to Mark a case as a 're-open' if the same Case Id occurred prior to the one being looked at
I have been trying a few various methods to see if I can get this to work, but I haven't had any luck.
Here is what I am trying to accomplish.
Every day, there are cases that get closed. We are ...
5
votes
5
answers
4k
views
SELECT TOP 2 MAX Value Group By SQL
I have the following table:
-----------------------------------------
xDate xItem xCount
-----------------------------------------
2018-01-01 A 100
2018-01-01 B ...
3
votes
2
answers
57
views
Apply group by on part of a column and get contradictions
Please consider this Table:
Id FullName Gender
---------------------------------------
1 Tom Hanksi Junior 1
2 Tom Cruisi 2
3 Meril ...
2
votes
2
answers
47
views
How to combine a result set into one row after using group by
The SQL script:
select can.Reference, can.CandidateID, can.firstname + ' ' + can.surname AS 'Candidate',
con.firstname + ' ' + con.lastname as 'Consultant', sector.unitname from candidate can
inner ...