Question

In: Computer Science

why would you want to use grouping in a query? Explain. Give Examples.

why would you want to use grouping in a query? Explain. Give Examples.

Solutions

Expert Solution

Answer)
In relational databases, SQL is used for performing the databases operations on the database. The grouping in a database query is used for arranging the identical data into the groups with the help of the functions.
Basically, the group by a statement in SQL is used to do the same. When the particular column has the same values in many rows of the table then we can arrange the rows in a grouping mechanism and thus view it as a short summary of the content of the table.

For example:
SELECT DEPT, SUM(SALARY) FROM Employee
GROUP BY DEPT;

The above SQL query is used to find out the department and the sum of all salaries of the employee who are in that department. Thus the sum function is used in this SQL query from the Employee table in the database, grouped by the DEPT column.

Another example can be:
SELECT DEPT, AVG(SALARY) FROM Employee
GROUP BY DEPT;

The above query is similar to the previous one, here the average of the salary is queried from the table Employee of employees who belong to the same department. Thus each department and average salaries are displayed using this query.


Related Solutions

Give at least three examples of when you would use ANOVA. Why would you use ANOVA...
Give at least three examples of when you would use ANOVA. Why would you use ANOVA as opposed to t-Tests to determine the mean differences? Which method do you feel is easier to comprehend?
Give two examples of fiscal stimuli and explain why a government would use these. Explain how...
Give two examples of fiscal stimuli and explain why a government would use these. Explain how can corporate tax cuts be an engine for economic growth. According to the RWM article, explain 2 ways in which the GOP Tax plan would increase income inequality
Recursion Discussions Question: Why would you want to use recursion? Concerning programming, when would you want...
Recursion Discussions Question: Why would you want to use recursion? Concerning programming, when would you want to use iterative vs. recursive programming? Where does coding fit in concerning the software process (i.e. its use in design, in coding, etc.)? Describe recursion problems, and why does it seem to fit with recursion? (e.g. nature, math, music, sports game, etc.)  
If you have a computer, why would you want an IP address? Why would you want...
If you have a computer, why would you want an IP address? Why would you want a URL? Would you ever want both? Why? Detailed answer please.
Give at least four examples of possible constraints. Explain why they would be constraints. From a...
Give at least four examples of possible constraints. Explain why they would be constraints. From a decision-making point of view, should joint costs be allocated among joint products? Explain. What, if any, benefit is provided by activity-based costing related to relevant costs and decision making?
Give examples of three prosocial behaviors you would want to teach young children. Have you ever...
Give examples of three prosocial behaviors you would want to teach young children. Have you ever taught these behaviors? If yes, how? Would you use particular discussion question when working with parents? If yes, why? If no, why not
a) Explain what is meant by UBV filters. b) Explain why astronomers would want to use...
a) Explain what is meant by UBV filters. b) Explain why astronomers would want to use such filters. c) Give an example of the usage of UBV filters.
Give two examples of where you have seen price discrimination and explain why they are examples.
Give two examples of where you have seen price discrimination and explain why they are examples.
if you want to increase aggregate supply what policy would you use? why?
if you want to increase aggregate supply what policy would you use? why?
Give examples of studies where in the null hypothesis would be the preferred use, and examples...
Give examples of studies where in the null hypothesis would be the preferred use, and examples of where the alternative hypothesis would be more useful.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT