SlideShare a Scribd company logo
10SQL SERVER: DOINGCALCULATIONS WITH FUNCTIONS
Mathematical FunctionsCan mathematical functions be used on my tables?	Yes. Microsoft SQL Server 2008 provides several mathematical functions such as sum(col), avg(col), min(col), max(col), count(col) etc. In SQL, they are referred to as aggregate functions as they work upon aggregates of rows.Functions Explained:Sum(fieldName): Find the sum of field values of all recordsAvg(fieldName): Find the average of field values of all recordsMin(fieldName): Find the minimum of the field values of all recordsMax(fieldName): Find the maximum of the field values of all recordsCount(fieldName): Find the number of field values in the table records
Mathematical FunctionsConsider an Interpol database which contains a table of the biggest robberies that took place this year, all around the world.Now, lets look into the application of math functions over this table.
Mathematical Functions1. Find the TOTAL booty of all the robberies:Select sum(booty) from robberies;2. Find the Average booty of all the robberies:Select avg(booty) from robberies;3. Find the robbery with the maximal bootySelect max(booty) from robberies;4. Find the robbery with the minimal bootySelect min(booty) from robberies;5. Find the number of robbery cases:Select count(booty) from robberies;
Using as conditionHEY??? I CANNOT USE THESE FUNCTIONS WITH MY ‘WHERE’ CONDITION???Microsoft SQL Server 2008 restricts the user to use these functions with ‘WHERE’ conditions. Therefore, to solve our problem three keywords: ‘having’, ‘any’ and ‘in’select * from tablename having <condition>;select * from tablename where colname=any(cond);select * from tablename where colname in (condition);
Advanced AggregatesIS THERE ANY OTHER MODIFICATION TO THESE FUNCTIONS?	We can combine these functions with ‘group by’ function for better results.select sum(col1),col2 from tablename group by col2;The above command will find out the sum of each group from column 2 More than one aggregate functions can be used simultaneously, seperated by commas.Eg: select sum(col1), count(col1) from tablename;Consider the example in the next slide.
Advanced AggregatesConsider an employee table:Find the Number of Employees working in each department:Select count(empid), depid from employee;Result:
Additional Functions upper (fieldName)Converts the value of fieldName to upper case. Can be used with strings. lower (fieldName)Converts the value of fieldName to lowercase. Can be used with strings.
Summary10. Doing Calculations with functions  Sum
Avg

More Related Content

PDF
Sql cheat-sheet
PPTX
Group functions
PPTX
Unit 6: Functions and Subroutines - Part 2/2
PPT
Computer notes - Hashing
PDF
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
PPT
computer notes - Data Structures - 35
PPT
MEngine Overview
PPTX
R: Apply Functions
Sql cheat-sheet
Group functions
Unit 6: Functions and Subroutines - Part 2/2
Computer notes - Hashing
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
computer notes - Data Structures - 35
MEngine Overview
R: Apply Functions

What's hot (19)

PPTX
PPTX
random forest regression
PPT
Mapreduce: Theory and implementation
PDF
PPTX
multiple linear regression
PPTX
simple linear regression
PPTX
decision tree regression
PDF
PART 6: FROM GEO INTO YOUR REPORT
PPTX
Sql FUNCTIONS
PPTX
c++ programming Unit 4 operators
PPT
Stack linked list
PDF
R-Excel Integration
PPTX
Presentation topic is stick data structure
PPTX
polynomial linear regression
PPTX
knn classification
PDF
PART 3: THE SCRIPTING COMPOSER AND PYTHON
PDF
PART 4: GEOGRAPHIC SCRIPTING
PDF
Java Week6(B) Notepad
PPTX
V22 function-1
random forest regression
Mapreduce: Theory and implementation
multiple linear regression
simple linear regression
decision tree regression
PART 6: FROM GEO INTO YOUR REPORT
Sql FUNCTIONS
c++ programming Unit 4 operators
Stack linked list
R-Excel Integration
Presentation topic is stick data structure
polynomial linear regression
knn classification
PART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 4: GEOGRAPHIC SCRIPTING
Java Week6(B) Notepad
V22 function-1
Ad

Viewers also liked (20)

PPTX
Matlab: Saving And Publishing
ODP
Oratoria E RetóRica Latinas
PPTX
R Statistics
PPTX
Quick Look At Clustering
PPTX
LISP: Scope and extent in lisp
PPTX
Txomin Hartz Txikia
PPT
Webmining Overview
PPTX
Clickthrough
KEY
Kidical Mass Presentation
PPTX
Data Applied: Association
PPTX
MS Sql Server: Manipulating Database
PPTX
Quick Look At Classification
PPTX
Continuous Random Variables
PPTX
MS SQL SERVER: Microsoft sequence clustering and association rules
PPTX
C,C++ In Matlab
PPTX
Procedures And Functions in Matlab
PPTX
LISP: Declarations In Lisp
PPTX
Matlab Text Files
PPTX
Matlab: Discrete Linear Systems
PPTX
Mysql:Operators
Matlab: Saving And Publishing
Oratoria E RetóRica Latinas
R Statistics
Quick Look At Clustering
LISP: Scope and extent in lisp
Txomin Hartz Txikia
Webmining Overview
Clickthrough
Kidical Mass Presentation
Data Applied: Association
MS Sql Server: Manipulating Database
Quick Look At Classification
Continuous Random Variables
MS SQL SERVER: Microsoft sequence clustering and association rules
C,C++ In Matlab
Procedures And Functions in Matlab
LISP: Declarations In Lisp
Matlab Text Files
Matlab: Discrete Linear Systems
Mysql:Operators
Ad

Similar to MS Sql Server: Doing Calculations With Functions (20)

PDF
2. mathematical functions in excel
PPT
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
PPTX
database_set_operations_&_function.pptx
PPTX
Empowerment-Technology-Microsoft-Excel.pptx
PPTX
Advanced Excel Functions in powerpoint presentation
PDF
Introduction to oracle functions
PDF
Chapter9 more on database and sql
PPT
MS SQL Server.ppt sql
PPT
Intro to tsql unit 10
DOC
Data Transformation
PDF
Structured query language(sql)
PPTX
My SQL.pptx
ODP
Mysql1
PDF
The Ring programming language version 1.8 book - Part 94 of 202
DOC
Sql Queries
PPTX
Lecture on the BASIC MICROSOFT EXCEL lectur
PDF
Sql wksht-3
PPTX
ADVANCE ITT BY PRASAD
PDF
The Ring programming language version 1.5.2 book - Part 175 of 181
2. mathematical functions in excel
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
database_set_operations_&_function.pptx
Empowerment-Technology-Microsoft-Excel.pptx
Advanced Excel Functions in powerpoint presentation
Introduction to oracle functions
Chapter9 more on database and sql
MS SQL Server.ppt sql
Intro to tsql unit 10
Data Transformation
Structured query language(sql)
My SQL.pptx
Mysql1
The Ring programming language version 1.8 book - Part 94 of 202
Sql Queries
Lecture on the BASIC MICROSOFT EXCEL lectur
Sql wksht-3
ADVANCE ITT BY PRASAD
The Ring programming language version 1.5.2 book - Part 175 of 181

More from DataminingTools Inc (20)

PPTX
Terminology Machine Learning
PPTX
Techniques Machine Learning
PPTX
Machine learning Introduction
PPTX
Areas of machine leanring
PPTX
AI: Planning and AI
PPTX
AI: Logic in AI 2
PPTX
AI: Logic in AI
PPTX
AI: Learning in AI 2
PPTX
AI: Learning in AI
PPTX
AI: Introduction to artificial intelligence
PPTX
AI: Belief Networks
PPTX
AI: AI & Searching
PPTX
AI: AI & Problem Solving
PPTX
Data Mining: Text and web mining
PPTX
Data Mining: Outlier analysis
PPTX
Data Mining: Mining stream time series and sequence data
PPTX
Data Mining: Mining ,associations, and correlations
PPTX
Data Mining: Graph mining and social network analysis
PPTX
Data warehouse and olap technology
PPTX
Data Mining: Data processing
Terminology Machine Learning
Techniques Machine Learning
Machine learning Introduction
Areas of machine leanring
AI: Planning and AI
AI: Logic in AI 2
AI: Logic in AI
AI: Learning in AI 2
AI: Learning in AI
AI: Introduction to artificial intelligence
AI: Belief Networks
AI: AI & Searching
AI: AI & Problem Solving
Data Mining: Text and web mining
Data Mining: Outlier analysis
Data Mining: Mining stream time series and sequence data
Data Mining: Mining ,associations, and correlations
Data Mining: Graph mining and social network analysis
Data warehouse and olap technology
Data Mining: Data processing

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Cloud computing and distributed systems.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
KodekX | Application Modernization Development
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Machine learning based COVID-19 study performance prediction
Diabetes mellitus diagnosis method based random forest with bat algorithm
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Artificial Intelligence
Network Security Unit 5.pdf for BCA BBA.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Cloud computing and distributed systems.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KodekX | Application Modernization Development
NewMind AI Monthly Chronicles - July 2025
NewMind AI Weekly Chronicles - August'25 Week I
20250228 LYD VKU AI Blended-Learning.pptx
cuic standard and advanced reporting.pdf
Big Data Technologies - Introduction.pptx
Understanding_Digital_Forensics_Presentation.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
“AI and Expert System Decision Support & Business Intelligence Systems”

MS Sql Server: Doing Calculations With Functions

  • 2. Mathematical FunctionsCan mathematical functions be used on my tables? Yes. Microsoft SQL Server 2008 provides several mathematical functions such as sum(col), avg(col), min(col), max(col), count(col) etc. In SQL, they are referred to as aggregate functions as they work upon aggregates of rows.Functions Explained:Sum(fieldName): Find the sum of field values of all recordsAvg(fieldName): Find the average of field values of all recordsMin(fieldName): Find the minimum of the field values of all recordsMax(fieldName): Find the maximum of the field values of all recordsCount(fieldName): Find the number of field values in the table records
  • 3. Mathematical FunctionsConsider an Interpol database which contains a table of the biggest robberies that took place this year, all around the world.Now, lets look into the application of math functions over this table.
  • 4. Mathematical Functions1. Find the TOTAL booty of all the robberies:Select sum(booty) from robberies;2. Find the Average booty of all the robberies:Select avg(booty) from robberies;3. Find the robbery with the maximal bootySelect max(booty) from robberies;4. Find the robbery with the minimal bootySelect min(booty) from robberies;5. Find the number of robbery cases:Select count(booty) from robberies;
  • 5. Using as conditionHEY??? I CANNOT USE THESE FUNCTIONS WITH MY ‘WHERE’ CONDITION???Microsoft SQL Server 2008 restricts the user to use these functions with ‘WHERE’ conditions. Therefore, to solve our problem three keywords: ‘having’, ‘any’ and ‘in’select * from tablename having <condition>;select * from tablename where colname=any(cond);select * from tablename where colname in (condition);
  • 6. Advanced AggregatesIS THERE ANY OTHER MODIFICATION TO THESE FUNCTIONS? We can combine these functions with ‘group by’ function for better results.select sum(col1),col2 from tablename group by col2;The above command will find out the sum of each group from column 2 More than one aggregate functions can be used simultaneously, seperated by commas.Eg: select sum(col1), count(col1) from tablename;Consider the example in the next slide.
  • 7. Advanced AggregatesConsider an employee table:Find the Number of Employees working in each department:Select count(empid), depid from employee;Result:
  • 8. Additional Functions upper (fieldName)Converts the value of fieldName to upper case. Can be used with strings. lower (fieldName)Converts the value of fieldName to lowercase. Can be used with strings.
  • 9. Summary10. Doing Calculations with functions Sum
  • 10. Avg
  • 15. Advanced groupingVisit more self help tutorialsPick a tutorial of your choice and browse through it at your own pace.The tutorials section is free, self-guiding and will not involve any additional support.Visit us at www.dataminingtools.net