Question

My SQL -----database----

What restrictions apply to the use of the aggregate functions within the SELECT statement? How do nulls affect the aggregate

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Following are the restrictions that apply to the aggregate functions within the select statement :

  1. Some of the aggregate functions(Sum and avg) can only be applied to numeric data.
  2. An aggregate function with a non-aggregate can't be used simultaneously in a single sql query.
  3. It usually ignores null values.

Null values are all ignored by the aggregate functions except in the case of count function.

Example: consider a table instructors as follows

Name Department salary Age
Arun Prakash cs 40000 45
sam allans ee 30000 52
charlie white cs 20000 57
joseph ee null 35
piyush cs null 30
ram mohan it 20000 40

joseph and piyush are newly joined so there salary are null.

if we want the salary of all the instructors paid by the college we can write the query :

select sum(salary) from instructor;

output is:

sum(salary)
110000

Group by clause is used when we have to apply aggregate functions for a group of set of tuples, it first groups the table according to some attribute and then apply the aggregate function on each group.

The where clause is used when we have to apply condition to tuples while the having clause is used when we have to apply condition to a group.

Example : if we want to find the average salary of all the departments where average salary is greater then 25000 we write the following query:

select department, avg(salary) from instructor group by department having avg(salary) > 25000;

output:

department avg(salary)
cs 30000
ee 30000
Add a comment
Know the answer?
Add Answer to:
My SQL -----database---- What restrictions apply to the use of the aggregate functions within the SELECT...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Top of Form Q1 Which of the following is a valid aggregate function in SQL? Check...

    Top of Form Q1 Which of the following is a valid aggregate function in SQL? Check only those that apply. Question 1 options: AVG LEAST COUNT MIN MOST SUM Q2 Which of the following aggregate functions will only operate on a numeric value expression? Check only those that apply: Question 2 options: MIN MAX AVG COUNT SUM Q3 When applying DISTINCT to the value being calculated in an aggregate function like COUNT, what is the effect? SELECT COUNT(DISTINCT StreetName) FROM...

  • I have this answer: SELECT c.Code, count(*) FROM country c JOIN countrylanguage cl ON c.Code =...

    I have this answer: SELECT c.Code, count(*) FROM country c JOIN countrylanguage cl ON c.Code = cl.CountryCode GROUP BY cl.CountryCode HAVING COUNT(*) > 1 LIMIT 10; From a previous question I asked which was: Using the database you installed from the link below, provide an example query using both a group by clause and a having clause. Show no more than ten rows of your query result. Discuss if the query you wrote can be rewritten without those clauses. The...

  • I have this answer: SELECT c.Code, count(*) FROM country c JOIN countrylanguage cl ON c.Code = cl.CountryCode GROUP BY c...

    I have this answer: SELECT c.Code, count(*) FROM country c JOIN countrylanguage cl ON c.Code = cl.CountryCode GROUP BY cl.CountryCode HAVING COUNT(*) > 1 LIMIT 10; From a previous question I asked which was: Using the database you installed from the link below, provide an example query using both a group by clause and a having clause. Show no more than ten rows of your query result. Discuss if the query you wrote can be rewritten without those clauses. The...

  • (TCO 7) Write a JOIN to display the instructor first and last names and the course...

    (TCO 7) Write a JOIN to display the instructor first and last names and the course description for the course the instructor is teaching Student Instructor Zipcode PK Student ID PK Instructor ID PK Zip Salutation First Name Last Name Street Address Phone Employer Registration Date Salutation First_Name Last_Name Street Address City State FK1 Zip FK1 Zip Section PK Section ID Course Course Section_Num Enrollment Start Date_Time Location PK Course ID PK,FK1 Section ID PK,FK2 Student ID Capacity FKI |...

  • QUESTION 21 Complete the table below by matching each definition with the appropriate SQL clause. -A.B.C.D.E.F.G.H.I.J.K.L.M.N....

    QUESTION 21 Complete the table below by matching each definition with the appropriate SQL clause. -A.B.C.D.E.F.G.H.I.J.K.L.M.N. A mandatory clause that is at the start of all SQL retrieval queries -A.B.C.D.E.F.G.H.I.J.K.L.M.N. A clause used to return only the values in a result table that are unique -A.B.C.D.E.F.G.H.I.J.K.L.M.N. A clause used to filter tuples according to some condition or predicate, like selection in relational algebra -A.B.C.D.E.F.G.H.I.J.K.L.M.N. A clause that is used to list the tables and any joins required in a query...

  • Create the database and tables for the database. Show all SQL statements. Include primary and foreign...

    Create the database and tables for the database. Show all SQL statements. Include primary and foreign keys. Insert data into each table. Show select statements and display the output of each table. Note:Student’s name must be inserted into table as part of the data! Perform the SQL below: Query one table and use WHERE to filter the results. The SELECT clause should have a column list, not an asterisk (*). State the purpose of the query; show the query and...

  • For all problems, use a single word alias (no quote marks) for any calculated fields. Limit...

    For all problems, use a single word alias (no quote marks) for any calculated fields. Limit long output to the first 5 rows by adding LIMIT 5 as the last row in your SQL select statement. Examples: SELECT AVG(amount) AS Avg_Payment LIMIT 5 The following questions use aggregate functions and all will require a GROUP BY clause. Some of them will require a HAVING clause if you are making selection criteria based on results from aggregated functions. 6. Show the...

  • Currently I am taking database management system and my teacher wants my to fill in these...

    Currently I am taking database management system and my teacher wants my to fill in these fill in the blank questions. 1.A single piece of data is a _______________________. 2.______________________________invented the first punched card. 3.Name one challenge with storing data today. 4.Software to manage data is called __________________________. 5.Herman Hollerith founded ______________________________. 6.DDL is known as ______________________________________. 7.A basic SQL statement has the following 3 parts _______________, _____________________ and __________________________. 8.In the like clause, what matches any group of characters...

  • SQL Question: 2. To limit the result-set to a defined set of requirements, what will a...

    SQL Question: 2. To limit the result-set to a defined set of requirements, what will a user do? A. Filter the database. B. Sort the database. C. Categorize the database. D. Group the database. 1. Which statement is used to retrieve data from more than one table? A. SELECT * FROM Customer B. SELECT * FROM Customer HAVING CustOrders C. ...FROM Customer WHERE... D. ...FROM Customer JOIN CustOrders ON...

  • Explain the SQL syntax along with how each statement functions SELECT UNIQUE Year_T FROM Wins_S001 WHERE...

    Explain the SQL syntax along with how each statement functions SELECT UNIQUE Year_T FROM Wins_S001 WHERE Team = 'Cardinals' OR LoserTeam = 'Cardinals';

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT