Concept explainers
WHERE Statement:
“WHERE” statement is used limit the number of rows. For example: Consider a table “FTable” that has two columns named “FruitName” and “Color”. “WHERE” clause is used when there is a need to display the entire FruitName whose color is Red.
SELECT * FROM FTable WHERE color = 'red';
When the above statement is executed, red colored fruits get displayed.
Grouping Rows:
SQL contains “GROUP BY” clause in order to group rows by common data. Though it is very powerful feature, it is hard to understand.
Syntax:
SELECT column_Name1 FROM table_Name GROUP BY column_Name2;
Example: Consider a table “student” contains two columns “student_Name” and “Department”. “GROUP BY” clause is used when there is a need to get the number of students from each department. The query for this scenario is given as follows.
SELECT department, COUNT (department) FROM student GROUP BY department;
When the above query is executed, number of students from each department will be displayed.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Database Systems: Design, Implementation, & Management
- Write the SQL code that will produce the same information that was shown in Problem 2, but sorted by the employee’s last name. The results of running that query are shown in Figure P7.3.arrow_forwardUse the following table to find the OUTPUT of the following SQL queries: Table Name: Patients MEDICAL_NO FIRST NAME SUR NAME DOB GENDER PHONE FAX BLOOD TYPE WEIGHT SMOKER PCR TEST 1001 Said Alalawi 12-Jun-2001 Male 98877445 22114454 A 68 NO Negative 1002 Othman Mualla 20-Apr-2000 Male B 78 YES Positive 1003 Sameera Bader 19-Oct-2005 Female 25541122 52 NO Positive 1004 Fahad Alhinai 24-Feb-2004 Male 91122544 AB 66 YES Negative 1005 Shamsa Alfahdi 15-Sep-2002 Female B 35 NO Negative SELECT SUM (weight) FROM patients WHERE pcr test= 'Positive'; Answer:arrow_forwardUse the following table to find the OUTPUT of the following SQL queries: Table Name: Patients MEDICAL_NO FIRST NAME SUR NAME DOB GENDER PHONE FAX BLOOD TYPE WEIGHT SMOKER PCR TEST 1001 Said Alalawi 12-Jun-2001 Male 98877445 22114454 A 68 NO Negative 1002 Othman Mualla 20-Apr-2000 Male B 78 YES Positive 1003 Sameera Bader 19-Oct-2005 Female 25541122 52 NO Positive 1004 Fahad Alhinai 24-Feb-2004 Male 91122544 AB 66 YES Negative 1005 Shamsa Alfahdi 15-Sep-2002 Female B Negative 35 NO SELECT NULLIF(phone, fax) FROM patients WHERE medical no = 1001; Answer:arrow_forward
- Use the following table to find the OUTPUT of the following SQL queries: Table Name: Patients MEDICAL_NO FIRST NAME SUR_NAME DOB GENDER PHONE FAX BLOOD TYPE WEIGHT SMOKER PCR TEST 1001 Said Alalawi 12-Jun-2001 Male 98877445 22114454 A 68 NO Negative 1002 Othman Mualla 20-Apr-2000 Male B 78 YES Positive 1003 Sameera Bader 19-Oct-2005 Female 25541122 52 NO Positive 1004 Fahad Alhinai 24-Feb-2004 Male Negative 91122544 AB 66 YES 1005 Shamsa Alfahdi 15-Sep-2002 Female 35 NO Negative SELECT NULLIF(phone, fax) FROM patients WHERE medical no = 1001; Answer:arrow_forwardUse the following table to find the OUTPUT of the following SQL queries: Table Name: Patients FIRST NAME SUR NAME BLOOD TYPE SMOKER MEDICAL NO DOB GENDER PHONE FAX WEIGHT PCR TEST 1001 Said Alalawi 12-Jun-2001 Male 98877445 22114454 A 68 NO Negative 1002 Othman Mualla 20-Apr-2000 Male B 78 YES Positive 1003 Sameera Bader 19-Oct-2005 Female 25541122 52 NO Positive 1004 Fahad Alhinai 24-Feb-2004 Male 91122544 AB 66 YES Negative 1005 Shamsa Alfahdi 15-Sep-2002 Female B 35 NO Negative SELECT TO CHAR (DOB, 'DD/YY/MM') FROM patients WHERE Medical no=1001; Answer:arrow_forwardUse the following table to find the OUTPUT of the following SQL queries: Table Name: Patients MEDICAL_NO FIRST_NAME SUR_NAME DOB GENDER PHONE FAX BLOOD TYPE WEIGHT SMOKER PCR TEST 1001 Said Alalawi 12-Jun-2001 Male 98877445 22114454 A 68 NO Negative 1002 Othman Mualla 20-Apr-2000 Male B 78 YES Positive 1003 Sameera Bader 19-Oct-2005 Female 25541122 52 NO Positive 1004 Fahad Alhinai 24-Feb-2004 Male 91122544 AB Negative 66 YES 1005 Shamsa Alfahdi 15-Sep-2002 Female B 35 NO Negative SELECT INSTR(first name, 'h') FROM patients WHERE medical no = 1002; Answer:arrow_forward
- Use the following table to find the OUTPUT of the following SQL queries: Table Name: Patients MEDICAL NO FIRST_NAME SUR NAME DOB GENDER PHONE FAX BLOOD TYPE WEIGHT SMOKER PCR TEST 1001 Said Alalawi 12-Jun-2001 Male 98877445 22114454 A 68 NO Negative 1002 Othman Mualla 20-Apr-2000 Male 78 VES Positive 1003 Sameera Bader 19-Oct-2005 Female 25541122 52 NO Positive 1004 Fahad Alhinai 24-Feb-2004 Male 91122544 AB 66 YES Negative 1005 Shamsa Alfahdi 15-Sep-2002 Female 35 NO Negative SELECT TO CHAR (DOB, 'Mon-DD-YY') FROM patients WHERE Medical no-1001; Answer: 12-Jun-2001arrow_forwardUse this info to answer the questionTABLE NAME: students COLUMNS:student-no NUMBER(6) fname VARCHAR2(12) lname VARCHAR(20) sex CHAR(1)major VARCHAR2(24) 7. Write a SQL statement that will display the student number(studentno),firstname(fname),and last name (lname) for all students who are female (F) in the table named students.arrow_forwardUsing the information in the ASSIGNMENT table, write SQL code that will return the total number of hours worked by each employee and the total cost of those hours, sorted by employee number.arrow_forward
- Use the following table to find the OUTPUT of the following SQL queries: Table Name: Patients MEDICAL NO FIRST NAME SUR NAME DOB GENDER BLOOD TYPE PCR TEST PHONE FAX WEIGHT SMOKER 1001 Said Alalawi 12-Jun-2001 Male 98877445 22114454 68 NO Negative 1002 Othman Mualla 20-Apr-2000 Male 78 YES Positive 1003 Sameera Bader 19-Oct-2005 Female 25541122 52 NO Positive 1004 Fahad Alhinal 24-Feb-2004 Male 91122544 AB 66 YES Negative 1005 Shamsa Alfahdi 15-Sep-2002 Female 35 NO Negative SELECT COALESCE (phone, fax, 9999) FROM patients WHERE blood_type='A'; Answer:arrow_forwardUse the following table to find the OUTPUT of the following SQL queries: Table Name: Patients MEDICAL_NO FIRST_NAME SUR_NAME DOB GENDER PHONE FAX BLOOD TYPE WEIGHT SMOKER PCR_TEST 1001 Said Alalawi 12-Jun-2001 Male 98877445 22114454 A. 68 NO Negative 1002 Othman Mualla 20-Apr-2000 Male B 78 YES Positive 1003 Sameera Bader 19-Oct-2005 Female 25541122 52 NO Positive 1004 Fahad Alhinai 24-Feb-2004 Male 91122544 AB 66 YES Negative 1005 Shamsa Alfahdi 15-Sep-2002 Female 35 NO Negative SELECT CONCAT (SUBSTR(first_name, 1,2), weight) FROM patients WHERE blood type= 'B' and weight > 70; Answer:arrow_forwardUse the following table to find the OUTPUT of the following SQL queries: Table Name: Patients MEDICAL_NO FIRST_NAME SUR_NAME DOB GENDER PHONE FAX BLOOD_TYPE WEIGHT SMOKER PCR_TEST 1001 Said Alalawi 12-Jun-2001 Male 98877445 22114454 A. 68 NO Negative 1002 Othman Mualla 20-Apr-2000 Male B 78 YES Positive 1003 Sameera Bader 19-Oct-2005 Female 25541122 52 NO Positive 1004 Fahad Alhinai 24-Feb-2004 Male 91122544 AB 66 YES Negative 1005 Shamsa Alfahdi 15-Sep-2002 Female 35 NO Negative SELECT LPAD(first name, 8, '@') FROM patients WHERE medical no = 1002; Answer:arrow_forward
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781285196145Author:Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos CoronelPublisher:Cengage LearningDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781305627482Author:Carlos Coronel, Steven MorrisPublisher:Cengage Learning
- A Guide to SQLComputer ScienceISBN:9781111527273Author:Philip J. PrattPublisher:Course Technology Ptr