Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Databases Programming Interviews:BtrieveClipperData ModelingData StructuresDatabase AdministrationDatabase Administrator (DBA)Database AnalystDatabase DeveloperDB DevelopmentEDI/Data Integration ExpertFirebirdHierarchicalIBM DB2InformixJava DatabaseMariaDBMicrosoft Access DeveloperMongoDBMS SQL ServerMySQL ProgrammingNetworkNoSQLObject RelationalPostgrePostgreSQLProgressRDBMSRelationalSQLSQL AdministratorSQL and PL/SQLSQL Notification ServicesSQL server 2008SSRSStored ProcedureSybaseTeradata
Copyright © 2018. All Rights Reserved
MS SQL Server Interview Question:
How To Use Group Functions in the SELECT Clause in MS SQL Server?
Submitted by: AdministratorIf group functions are used in the SELECT clause, all rows that meet the criteria defined in the WHERE clause will be treated as a single group. The group functions will be apply all rows in that group as a whole. The final output of the SELECT statement is the resulting values of the group functions, not the rows in the group. Here are two good examples of using group functions :
SELECT COUNT(*), MAX(counts), MIN(created)
FROM ggl_links
GO
COUNT(*) MAX(counts) MIN(created)
7 972 2003-01-01
SELECT COUNT(*), MAX(counts), MIN(created)
FROM ggl_links WHERE tag = 'DBA'
GO
COUNT(*) MAX(counts) MIN(created)
3 972 2005-01-01
In first case, the group contains all the rows in table ggl_links, because is no WHERE clause. In the second case, the group contains only 3 rows because of the WHERE clause tag = 'DBA'.
Submitted by: Administrator
SELECT COUNT(*), MAX(counts), MIN(created)
FROM ggl_links
GO
COUNT(*) MAX(counts) MIN(created)
7 972 2003-01-01
SELECT COUNT(*), MAX(counts), MIN(created)
FROM ggl_links WHERE tag = 'DBA'
GO
COUNT(*) MAX(counts) MIN(created)
3 972 2005-01-01
In first case, the group contains all the rows in table ggl_links, because is no WHERE clause. In the second case, the group contains only 3 rows because of the WHERE clause tag = 'DBA'.
Submitted by: Administrator
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.