Question

In: Computer Science

What single query can get data from 4 tables , using SUM or COUNT

What single query can get data from 4 tables , using SUM or COUNT

Solutions

Expert Solution

Sum() returns the total sum of a numeric column. count() returns the number of rows that matches a specific condition from the table. With out giving condition also we can give count(), so that it returns the total count of rows in the table.

Here we use sum of count from the 4 tables, so that sum() and count() will be there in the query.

To get sum of values from a table, sum() is used. Sum() can store a variable or temporary column (alias), same with count() also. Union all command combines the result set of 2 or more select statements. Union all will take duplicate values also.

So the query is:

SELECT SUM(ALIAS) [AS COLUMNNAME] FROM ((SELECT COUNT(*) AS ALIAS FROM TABLE1) UNION ALL(SELECT COUNT(*) AS ALIAS FROM TABLE2) UNION ALL(SELECT COUNT(*) AS ALIAS FROM TABLE3) UNION ALL(SELECT COUNT(*) AS ALIAS FROM TABLE4))ALIAS;

EXAMPLE:

SELECT SUM(ALLCOUNT) AS TOTALCOUNT FROM ((SELECT COUNT(*) AS ALLCOUNT FROM EMPLOYEES) UNION ALL(SELECT COUNT(*) AS ALLCOUNT FROM IRAS) UNION ALL(SELECT COUNT(*) AS ALLCOUNT FROM ADDRESSCITY) UNION ALL(SELECT COUNT(*) AS ALLCOUNT FROM COMPANT))T;


Related Solutions

To get from Earth to Jupiter spacecraft follow the Hohmann Transfer orbit. Using data, you can...
To get from Earth to Jupiter spacecraft follow the Hohmann Transfer orbit. Using data, you can find online for the orbits of Earth, Jupiter and the Sun (don’t forget to cite it), and assuming that the orbits of Earth and Jupiter are circular with radii equal to their semi-major axes: a. Determine the semi-major axis of the Hohmann transfer orbit? b. Determine the speed of the spacecraft at the Earth’s orbit in the hohmann transfer orbit? c. Determine the speed...
To get from Earth to Jupiter spacecraft follow the Hohmann Transfer orbit. Using data, you can...
To get from Earth to Jupiter spacecraft follow the Hohmann Transfer orbit. Using data, you can find online for the orbits of Earth, Jupiter and the Sun (don’t forget to cite it), and assuming that the orbits of Earth and Jupiter are circular with radii equal to their semi-major axes: b. Determine the speed of the spacecraft at the Earth’s orbit in the hohmann transfer orbit? a. Determine the semi-major axis of the Hohmann transfer orbit?
What observation can I get from Circulation measurement using Sphygmomanometer and plethysmograph?
What observation can I get from Circulation measurement using Sphygmomanometer and plethysmograph?
In what circumstances is data visualization better than using text explanations and tables of numeric data?...
In what circumstances is data visualization better than using text explanations and tables of numeric data? In what situations is it worse? Justify your reasoning.
For the following exercises, express each description of a sum using summation notation. The sum from of n = 0 to n = 4 of 5n
For the following exercises, express each description of a sum using summation notation.The sum from of n = 0 to n = 4 of 5n
What is a Data Dictionary? What is a Database Engine? What is a Query Processor/Analyzer? What...
What is a Data Dictionary? What is a Database Engine? What is a Query Processor/Analyzer? What is a Forms Generator? What is a Reports writer? What is a DBMS? What is the difference between DB and DBMS?
Question No 3. Tests Using Contingency Tables: A researcher selected sample of customs from 4 companies...
Question No 3. Tests Using Contingency Tables: A researcher selected sample of customs from 4 companies and asked them if the companies care give warranty on sold items or not. Assume observed values from your own (fill the below table by assuming any values of your choice) and test the claim that the proportion of customers of each company who got warranty is the same for each company by choosing alpha of your own choice.  (Marks 2.5) Company A Company B...
Question No 3. Tests Using Contingency Tables: A researcher selected sample of customs from 4 companies...
Question No 3. Tests Using Contingency Tables: A researcher selected sample of customs from 4 companies and asked them if the companies care give warranty on sold items or not. Assume observed values from your own (fill the below table by assuming any values of your choice) and test the claim that the proportion of customers of each company who got warranty is the same for each company by choosing alpha of your own choice.  (Marks 2.5) Company A Company B...
1. Write a query to: a. select data from INVOICES table as follows: Invoice date in...
1. Write a query to: a. select data from INVOICES table as follows: Invoice date in MM/DD/YYYY format Invoice Date in DD-Mon-YYYY format Invoice Total rounded to the nearest dollar Note: you can alias columns as you sit fit b. select data from VENDORS table as follows: Vendor Name Concatenate Vendor Name with the string ‘s Address Concatenate Vendor City, Vendor State and Vendor Zip Code (alias this) Your output should look like this (this is just an example of...
How can I get ATP and NADPH from DHAP using glycolysis and PPP?
How can I get ATP and NADPH from DHAP using glycolysis and PPP?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT