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
Steve Tran
 
PPTX
Group functions
sehrishishaq1
 
PPTX
Unit 6: Functions and Subroutines - Part 2/2
Matthew Campbell, OCT
 
PPT
Computer notes - Hashing
ecomputernotes
 
PDF
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
The Statistical and Applied Mathematical Sciences Institute
 
PPT
computer notes - Data Structures - 35
ecomputernotes
 
PPT
MEngine Overview
euming
 
PPTX
R: Apply Functions
DataminingTools Inc
 
Sql cheat-sheet
Steve Tran
 
Group functions
sehrishishaq1
 
Unit 6: Functions and Subroutines - Part 2/2
Matthew Campbell, OCT
 
Computer notes - Hashing
ecomputernotes
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
The Statistical and Applied Mathematical Sciences Institute
 
computer notes - Data Structures - 35
ecomputernotes
 
MEngine Overview
euming
 
R: Apply Functions
DataminingTools Inc
 

What's hot (19)

PPTX
Lesson9
Alex Honcharuk
 
PPTX
random forest regression
Akhilesh Joshi
 
PPT
Mapreduce: Theory and implementation
Sri Prasanna
 
PDF
Excel/R
Andrija Djurovic
 
PPTX
multiple linear regression
Akhilesh Joshi
 
PPTX
simple linear regression
Akhilesh Joshi
 
PPTX
decision tree regression
Akhilesh Joshi
 
PDF
PART 6: FROM GEO INTO YOUR REPORT
Andrea Antonello
 
PPTX
Sql FUNCTIONS
Abrar ali
 
PPTX
c++ programming Unit 4 operators
AAKASH KUMAR
 
PPT
Stack linked list
bhargav0077
 
PDF
R-Excel Integration
Andrija Djurovic
 
PPTX
Presentation topic is stick data structure
AizazAli21
 
PPTX
polynomial linear regression
Akhilesh Joshi
 
PPTX
knn classification
Akhilesh Joshi
 
PDF
PART 3: THE SCRIPTING COMPOSER AND PYTHON
Andrea Antonello
 
PDF
PART 4: GEOGRAPHIC SCRIPTING
Andrea Antonello
 
PDF
Java Week6(B) Notepad
Chaitanya Rajkumar Limmala
 
PPTX
V22 function-1
Dhirendra Chauhan
 
random forest regression
Akhilesh Joshi
 
Mapreduce: Theory and implementation
Sri Prasanna
 
multiple linear regression
Akhilesh Joshi
 
simple linear regression
Akhilesh Joshi
 
decision tree regression
Akhilesh Joshi
 
PART 6: FROM GEO INTO YOUR REPORT
Andrea Antonello
 
Sql FUNCTIONS
Abrar ali
 
c++ programming Unit 4 operators
AAKASH KUMAR
 
Stack linked list
bhargav0077
 
R-Excel Integration
Andrija Djurovic
 
Presentation topic is stick data structure
AizazAli21
 
polynomial linear regression
Akhilesh Joshi
 
knn classification
Akhilesh Joshi
 
PART 3: THE SCRIPTING COMPOSER AND PYTHON
Andrea Antonello
 
PART 4: GEOGRAPHIC SCRIPTING
Andrea Antonello
 
Java Week6(B) Notepad
Chaitanya Rajkumar Limmala
 
V22 function-1
Dhirendra Chauhan
 
Ad

Viewers also liked (20)

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

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

PDF
2. mathematical functions in excel
Dr. Prashant Vats
 
PPT
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
अभिषेक शर्मा
 
PPTX
database_set_operations_&_function.pptx
tanvirkhanfahim
 
PPTX
Empowerment-Technology-Microsoft-Excel.pptx
JohnMeja11
 
PPTX
Advanced Excel Functions in powerpoint presentation
SurendraKumarM1
 
PDF
Introduction to oracle functions
Nitesh Singh
 
PDF
Chapter9 more on database and sql
KV(AFS) Utarlai, Barmer (Rajasthan)
 
PPT
MS SQL Server.ppt sql
NaheedBaloxh
 
PPT
Intro to tsql unit 10
Syed Asrarali
 
DOC
Data Transformation
ArmanArafatAnik
 
PDF
Structured query language(sql)
Huda Alameen
 
PPTX
My SQL.pptx
KieveBarreto1
 
ODP
Mysql1
rajikaa
 
PDF
The Ring programming language version 1.8 book - Part 94 of 202
Mahmoud Samir Fayed
 
DOC
Sql Queries
webicon
 
PPTX
Lecture on the BASIC MICROSOFT EXCEL lectur
Bono42
 
PDF
Sql wksht-3
Mukesh Tekwani
 
PPTX
ADVANCE ITT BY PRASAD
PADYALAMAITHILINATHA
 
PDF
The Ring programming language version 1.5.2 book - Part 175 of 181
Mahmoud Samir Fayed
 
2. mathematical functions in excel
Dr. Prashant Vats
 
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
अभिषेक शर्मा
 
database_set_operations_&_function.pptx
tanvirkhanfahim
 
Empowerment-Technology-Microsoft-Excel.pptx
JohnMeja11
 
Advanced Excel Functions in powerpoint presentation
SurendraKumarM1
 
Introduction to oracle functions
Nitesh Singh
 
Chapter9 more on database and sql
KV(AFS) Utarlai, Barmer (Rajasthan)
 
MS SQL Server.ppt sql
NaheedBaloxh
 
Intro to tsql unit 10
Syed Asrarali
 
Data Transformation
ArmanArafatAnik
 
Structured query language(sql)
Huda Alameen
 
My SQL.pptx
KieveBarreto1
 
Mysql1
rajikaa
 
The Ring programming language version 1.8 book - Part 94 of 202
Mahmoud Samir Fayed
 
Sql Queries
webicon
 
Lecture on the BASIC MICROSOFT EXCEL lectur
Bono42
 
Sql wksht-3
Mukesh Tekwani
 
ADVANCE ITT BY PRASAD
PADYALAMAITHILINATHA
 
The Ring programming language version 1.5.2 book - Part 175 of 181
Mahmoud Samir Fayed
 

More from DataminingTools Inc (20)

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

Recently uploaded (20)

PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
PPTX
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
PDF
Software Development Methodologies in 2025
KodekX
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Doc9.....................................
SofiaCollazos
 
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Software Development Company | KodekX
KodekX
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
Software Development Methodologies in 2025
KodekX
 

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