Some Basic Aggregate Functions FUNCTION OUTPUT The number of rows containing non-null values The maximum attribute value encountered in a given column

Similar documents
Comparison Operators. Selecting Rows with Conditional Restrictions

Chapter # 7 Introduction to Structured Query Language (SQL) Part II

Databases - 5. Problems with the relational model Functions and sub-queries

CSC Web Programming. Introduction to SQL

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS. The foundation of good database design

Introduction to SQL. From Rob and Coronel (2004), Database Systems: Design, Implementation, and Management

HKTA TANG HIN MEMORIAL SECONDARY SCHOOL SECONDARY 3 COMPUTER LITERACY. Name: ( ) Class: Date: Databases and Microsoft Access

SQL functions fit into two broad categories: Data definition language Data manipulation language

COMP 244 DATABASE CONCEPTS & APPLICATIONS

Lab # 4 Hands-On. DDL and DML Advance SQL Statements Institute of Computer Science, University of Tartu, Estonia

Chapter-14 SQL COMMANDS

DB-Queries-1 - REVIEW Individual 20 Points

1) Introduction to SQL

GIFT Department of Computing Science. CS-217: Database Systems. Lab-4 Manual. Reporting Aggregated Data using Group Functions

In This Lecture. Yet More SQL SELECT ORDER BY. SQL SELECT Overview. ORDER BY Example. ORDER BY Example. Yet more SQL

UNIT III INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL)

Data Manipulation Language (DML)

Visit for more.

Lecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University


Introduction to Functions and Variables

You can write a command to retrieve specified columns and all rows from a table, as illustrated

What Are Group Functions? Reporting Aggregated Data Using the Group Functions. Objectives. Types of Group Functions

CS2 Current Technologies Lecture 2: SQL Programming Basics

2) SQL includes a data definition language, a data manipulation language, and SQL/Persistent stored modules. Answer: TRUE Diff: 2 Page Ref: 36

STOP DROWNING IN DATA. START MAKING SENSE! An Introduction To SQLite Databases. (Data for this tutorial at

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition

Teradata SQL Features Overview Version

SQL. SQL Functions. SQL Aggregate Functions. SQL Scalar functions. SQL Aggregate Functions. The AVG() Function

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement

Simple SQL Queries (2)

Relational Database Management Systems for Epidemiologists: SQL Part I

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

Intermediate SQL: Aggregated Data, Joins and Set Operators

Database Management Systems by Hanh Pham GOALS

Preview. Advanced SQL. In this chapter, you will learn:

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

Test Bank for Database Processing Fundamentals Design and Implementation 13th Edition by Kroenke

GIFT Department of Computing Science. [Spring 2016] CS-217: Database Systems. Lab-3 Manual. Single Row Functions in SQL

SYSTEM CODE COURSE NAME DESCRIPTION SEM

CST272 SQL Server, SQL and the SqlDataSource Page 1

Relational Database Language

Full file at

SQL FUNCTIONS. Prepared By:Dr. Vipul Vekariya.

Announcements (September 14) SQL: Part I SQL. Creating and dropping tables. Basic queries: SFW statement. Example: reading a table

This course is aimed at those who need to extract information from a relational database system.

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints

Based on the following Table(s), Write down the queries as indicated: 1. Write an SQL query to insert a new row in table Dept with values: 4, Prog, MO

Lesson 2. Data Manipulation Language

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

COGS 121 HCI Programming Studio. Week 03 - Tech Lecture

Downloaded from

PRACTICAL LIST FOR ODD SEMESTERS Session (PGDCA/MCA/MSC (CS))

SQL. Char (30) can store ram, ramji007 or 80- b

Structured Query Language: Introduction

More MySQL ELEVEN Walkthrough examples Walkthrough 1: Bulk loading SESSION

Top 10 SAS Functions in A brief summary of SAS Communities Survey - by Flora Fang Liu

DS Introduction to SQL Part 1 Single-Table Queries. By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford)

ASSIGNMENT NO Computer System with Open Source Operating System. 2. Mysql

SQL. Rodrigo García Carmona Universidad San Pablo-CEU Escuela Politécnica Superior

B. V. Patel Institute of Business Management, Computer & Information Technology, UTU 2013

SQL 2 (The SQL Sequel)

Oracle Database 11g: SQL and PL/SQL Fundamentals

Deepak Bhinde PGT Comp. Sc.

Structure Query Language (SQL)

Stat Wk 3. Stat 342 Notes. Week 3, Page 1 / 71

Lab # 6. Using Subqueries and Set Operators. Eng. Alaa O Shama

3/3/2008. Announcements. A Table with a View (continued) Fields (Attributes) and Primary Keys. Video. Keys Primary & Foreign Primary/Foreign Key

Data about data is database Select correct option: True False Partially True None of the Above

The query language for relational databases Jef De Smedt

Rani Durgavati Vishwavidyalaya Jabalpur (M.P.) (UICSA) Master of Computer Application (MCA) Practical List of. MCA III SEM Session -2010

Lab # 3 Hands-On. DML Basic SQL Statements Institute of Computer Science, University of Tartu, Estonia

DATABASE TECHNOLOGY - 1MB025

Oracle Syllabus Course code-r10605 SQL

Subquery: There are basically three types of subqueries are:

This lab will introduce you to MySQL. Begin by logging into the class web server via SSH Secure Shell Client

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

DATABASTEKNIK - 1DL116

Unit 4. Scalar Functions and Arithmetic

Bsc (Hons) Software Engineering. Examinations for / Semester 1. Resit Examinations for BSE/15A/FT & BSE/16A/FT

Activant Solutions Inc. SQL 2005: Basic Data Manipulation

Lab 6 Counting with SQL

Relational Database Development

SQL Server Administration Class 4 of 4. Activant Prophet 21. Basic Data Manipulation

Name Section: M/W or T/TH. True or False (14 Points)

CS 275 Winter 2011 Problem Set 3

Database implementation Further SQL

SQL Data Manipulation Language. Lecture 5. Introduction to SQL language. Last updated: December 10, 2014

THE INDIAN COMMUNITY SCHOOL, KUWAIT

CMP-3440 Database Systems

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

SQL (Structured Query Language)

Structure Query Language (SQL)

ITEC212 Database Management Systems Laboratory 2

Chapter 4: Control structures. Repetition

Review. Objec,ves. Example Students Table. Database Overview 3/8/17. PostgreSQL DB Elas,csearch. Databases

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

Basic SQL. Dr Paolo Guagliardo. University of Edinburgh. Fall 2016

Transcription:

SQL Functions Aggregate Functions Some Basic Aggregate Functions OUTPUT COUNT() The number of rows containing non-null values MIN() The minimum attribute value encountered in a given column MAX() The maximum attribute value encountered in a given column SUM() The sum of all values for a given column AVG() The arithmetic mean (average) for a given column Table 1 COUNT [WHERE COUNT (columnname) tablename conditionlist] Example: How many students are born in New York? COUNT (*) WHERE CITY LIKE New York MIN and MAX Figure 1 Example (see Figure 1): 1. Which product has the highest price? MAX (P_PRICE) PRODUCT NOTE: The aggregate functions MAX(columnlist) and MIN(columnlist) can be used only in the column list of a statement 2. Which product has the lowest price? MIN (P_PRICE) PRODUCT

SUM Find the total value of all items carried in the inventory. SUM(P_QOH * P_PRICE) AS TOTALVALUE PRODUCT AVG AVG(P_PRICE) PRODUCT Date/Time Functions Selected Date/Time Functions YEAR(date_value) MONTH(date_value) DAY(date_value) DATE() NOW() Returns a four digit year Returns a two-digit month code Returns the number of the day Displays the current date Displays the current date and time. YEAR: List all students born in 1985 * WHERE YEAR(STUD_DOB) = 1985 MONTH: List all students born in November * WHERE MONTH(STUD_DOB) = 11 DAY: List all students born on the 14 th day of the month. * WHERE DAY(STUD_DOB) = 14 DATE(): List how many days are left until Christmas: #25-12-2014# - DATE() Add/subtract a number of days to a given date DATE() +/- 90

Numeric functions Selected Numeric Functions ABS(numeric_value) ROUND(numeric_value, p) p= precision INT(numeric_value) FIX(numeric_value) Returns the absolute value of a number Rounds a value to a specified precision Returns the integer portion of a number. if number is negative, INT returns the first negative integer less than or equal to number Returns the integer portion of a number. if number is negative, FIX returns the first negative integer greater than or equal to number ABS(-5.6) Output: 5.6 ROUND(PROD_PRICE, 1) PRODUCT INT(-5,6) Output: -6 FIX(-5.6) Output: -5 String Functions Selected String Function Concatenation string_value+ string_value UCASE and LCASE MID(string_value, p,l) p- start position ; l length of characters LEN(string_value) Concatenates date from two different character columns and returns a single value Returns a string with all capitals or lowercase letters Returns a substring or a part of a given string parameter Returns the number of characters in a string value List all student names (concatenated) STUD_FNAME +' '+ STUD_LNAME AS STUDNAME STUDENT List all student names in all capital letters UCASE(STUD_FNAME) +' '+ UCASE(STUD_LNAME) AS STUDNAME List the first three characters of all students phone numbers. MID(STUD_PHONE, 1, 3) AS PREFIX

List all students last names and the number of their characters in descending order by last name length. STUD_LNAME, LEN(STUD_LNAME) ORDER BY LEN(STUD_LNAME) DESC Problems: Use figure P1 to solve the following problems: Figure P1 Construct database 1. Write the SQL code to find the average bonus percentage in the EMP_2 table you created. 2. Write a query to count the number of employees hired from the company. 3. Write a query to count the number of projects with balance greater than 1 000 000. 4. Write a query to show the value of the most expensive project 5. Write a query to show the value of the most expensive project and the project s name. (Figure 2)(Hint: Use a nested query) Figure 2 6. Write a query to show first and last names, and hire date of the newly hired employee. Figure 3

7. Write the SQL code to fix the values in ASSIGN_CHARGE column in ASSIGNMENT table as shown in Figure P1 (Use numeric function ) 8. Count the number of different job codes assigned to project with number 15. (Hint: Use a nested query (see: lab 2) ) 9. Write the queries for the rest of the projects. (PROJ_NUM : 18, 22, 25) 10. List all employees names concatenated in all capital letters 11. Calculate the total money charged to the employees on 22.March.2012. 12. Calculate the total money charged to the employees on 22.March.2012 worked on Starflight project.