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

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
 

Viewers also liked (15)

PPTX
MS SQL SERVER: Introduction To Database Concepts
sqlserver content
 
PPTX
MS SQLSERVER:Manipulating Database
sqlserver content
 
PPTX
MS Sql Server: Reporting basics
sqlserver content
 
PPTX
MS Sql Server: Datamining Introduction
sqlserver content
 
PPTX
MS SQL SERVER: Microsoft sequence clustering and association rules
sqlserver content
 
PPTX
MS SQL SERVER: Using the data mining tools
sqlserver content
 
PPTX
MS SQL SERVER: Creating A Database
sqlserver content
 
PPTX
MS SQL SERVER: Neural network and logistic regression
sqlserver content
 
PPTX
MS Sql Server: Business Intelligence
sqlserver content
 
PPTX
MS Sql Server: Reporting introduction
sqlserver content
 
PPTX
MS SQLSERVER:Feeding Data Into Database
sqlserver content
 
PPTX
MS SQLSERVER:Retrieving Data From A Database
sqlserver content
 
PPTX
MS SQL SERVER: SSIS and data mining
sqlserver content
 
PPTX
MS SQLSERVER:Joining Databases
sqlserver content
 
PPTX
MS SQL SERVER: Getting Started With Sql Server 2008
sqlserver content
 
MS SQL SERVER: Introduction To Database Concepts
sqlserver content
 
MS SQLSERVER:Manipulating Database
sqlserver content
 
MS Sql Server: Reporting basics
sqlserver content
 
MS Sql Server: Datamining Introduction
sqlserver content
 
MS SQL SERVER: Microsoft sequence clustering and association rules
sqlserver content
 
MS SQL SERVER: Using the data mining tools
sqlserver content
 
MS SQL SERVER: Creating A Database
sqlserver content
 
MS SQL SERVER: Neural network and logistic regression
sqlserver content
 
MS Sql Server: Business Intelligence
sqlserver content
 
MS Sql Server: Reporting introduction
sqlserver content
 
MS SQLSERVER:Feeding Data Into Database
sqlserver content
 
MS SQLSERVER:Retrieving Data From A Database
sqlserver content
 
MS SQL SERVER: SSIS and data mining
sqlserver content
 
MS SQLSERVER:Joining Databases
sqlserver content
 
MS SQL SERVER: Getting Started With Sql Server 2008
sqlserver content
 
Ad

Similar to MS SQLSERVER:Doing Calculations With Functions (20)

PPTX
Aggregate Function - Database
Shahadat153031
 
PDF
SQL-AGG-FUN.pdfiiiijuyyttfffgyyuyyyyyhhh
NaveeN547338
 
PPT
PHP mysql Aggregate functions
Mudasir Syed
 
PPTX
AGGREGATE FUNCTION.pptx
Anusha sivakumar
 
DOCX
Database Query Using SQL_ip.docx
VandanaGoyal21
 
PPS
03 qmds2005 session03
Niit Care
 
RTF
Sql functions
ilias ahmed
 
PPT
Aggregate Functions,Final
mukesh24pandey
 
PPT
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
अभिषेक शर्मा
 
PPTX
aggregatefunction-220420051702.pptx aggregate
sadiariasat10
 
PDF
0716330552518_DBMS_LAB_THEORY_SQL_OPERATOR (1).pdf
sahilurrahemankhan
 
PDF
Sql wksht-3
Mukesh Tekwani
 
PPTX
SQL.pptx
MrHello6
 
PPTX
DBMS: Week 07 - Advanced SQL Queries in MySQL
RashidFaridChishti
 
PDF
Introduction to oracle functions
Nitesh Singh
 
PPTX
database_set_operations_&_function.pptx
tanvirkhanfahim
 
PDF
MySQL-commands.pdf
ssuserc5aa74
 
PPT
Sql group functions
Sumit Tambe
 
PPT
Sql group functions(2)
Sumit Tambe
 
PPTX
Aggregate function
Rayhan Chowdhury
 
Aggregate Function - Database
Shahadat153031
 
SQL-AGG-FUN.pdfiiiijuyyttfffgyyuyyyyyhhh
NaveeN547338
 
PHP mysql Aggregate functions
Mudasir Syed
 
AGGREGATE FUNCTION.pptx
Anusha sivakumar
 
Database Query Using SQL_ip.docx
VandanaGoyal21
 
03 qmds2005 session03
Niit Care
 
Sql functions
ilias ahmed
 
Aggregate Functions,Final
mukesh24pandey
 
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
अभिषेक शर्मा
 
aggregatefunction-220420051702.pptx aggregate
sadiariasat10
 
0716330552518_DBMS_LAB_THEORY_SQL_OPERATOR (1).pdf
sahilurrahemankhan
 
Sql wksht-3
Mukesh Tekwani
 
SQL.pptx
MrHello6
 
DBMS: Week 07 - Advanced SQL Queries in MySQL
RashidFaridChishti
 
Introduction to oracle functions
Nitesh Singh
 
database_set_operations_&_function.pptx
tanvirkhanfahim
 
MySQL-commands.pdf
ssuserc5aa74
 
Sql group functions
Sumit Tambe
 
Sql group functions(2)
Sumit Tambe
 
Aggregate function
Rayhan Chowdhury
 
Ad

More from sqlserver content (18)

PPTX
MS SQL SERVER: Programming sql server data mining
sqlserver content
 
PPTX
MS SQL SERVER: Olap cubes and data mining
sqlserver content
 
PPTX
MS SQL SERVER: Microsoft time series algorithm
sqlserver content
 
PPTX
MS SQL SERVER: Microsoft naive bayes algorithm
sqlserver content
 
PPTX
MS SQL SERVER: Decision trees algorithm
sqlserver content
 
PPTX
MS SQL Server: Data mining concepts and dmx
sqlserver content
 
PPTX
MS Sql Server: Reporting models
sqlserver content
 
PPTX
MS Sql Server: Reporting manipulating data
sqlserver content
 
PPTX
MS SQLSERVER:Deleting A Database
sqlserver content
 
PPTX
MS SQLSERVER:Customizing Your D Base Design
sqlserver content
 
PPTX
MS SQLSERVER:Creating Views
sqlserver content
 
PPTX
MS SQLSERVER:Creating A Database
sqlserver content
 
PPTX
MS SQLSERVER:Advanced Query Concepts Copy
sqlserver content
 
PPTX
MS SQLSERVER:Sql Functions And Procedures
sqlserver content
 
PPTX
MS SQL SERVER: Sql Functions And Procedures
sqlserver content
 
PPTX
MS SQL SERVER: Retrieving Data From A Database
sqlserver content
 
PPTX
MS SQL SERVER: Manipulating Database
sqlserver content
 
PPTX
MS SQL SERVER: Joining Databases
sqlserver content
 
MS SQL SERVER: Programming sql server data mining
sqlserver content
 
MS SQL SERVER: Olap cubes and data mining
sqlserver content
 
MS SQL SERVER: Microsoft time series algorithm
sqlserver content
 
MS SQL SERVER: Microsoft naive bayes algorithm
sqlserver content
 
MS SQL SERVER: Decision trees algorithm
sqlserver content
 
MS SQL Server: Data mining concepts and dmx
sqlserver content
 
MS Sql Server: Reporting models
sqlserver content
 
MS Sql Server: Reporting manipulating data
sqlserver content
 
MS SQLSERVER:Deleting A Database
sqlserver content
 
MS SQLSERVER:Customizing Your D Base Design
sqlserver content
 
MS SQLSERVER:Creating Views
sqlserver content
 
MS SQLSERVER:Creating A Database
sqlserver content
 
MS SQLSERVER:Advanced Query Concepts Copy
sqlserver content
 
MS SQLSERVER:Sql Functions And Procedures
sqlserver content
 
MS SQL SERVER: Sql Functions And Procedures
sqlserver content
 
MS SQL SERVER: Retrieving Data From A Database
sqlserver content
 
MS SQL SERVER: Manipulating Database
sqlserver content
 
MS SQL SERVER: Joining Databases
sqlserver content
 

Recently uploaded (20)

PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
Digital Circuits, important subject in CS
contactparinay1
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 

MS SQLSERVER: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