Question

In: Computer Science

Using SQL, answer the following question referring to the table below How many twins are there?...

  1. Using SQL, answer the following question referring to the table below
    1. How many twins are there? (Just having the same birthday does not make you twins.)
    1. Name the twins.

CREATE TABLE IF NOT EXISTS students (

student_id INT NOT NULL AUTO_INCREMENT,

first_name VARCHAR(16),

last_name VARCHAR(24),

birthday DATE,

street_address VARCHAR(128),

city VARCHAR(32),

PRIMARY KEY (student_id));

INSERT INTO students

(first_name, last_name, birthday, street_address, city) VALUES

('John','Jones','2000-12-17','250 Pines Blvd.','Pembroke Pines'),

('Mark','Bacon','2000-04-12','1270 Walnut St.','Prarie Bluff'),

('Bill','Carlson','1999-07-06','250 Pines Blvd.','Pembroke Pines'),

('Jean','Carlson','1999-07-06','250 Pines Blvd.','Pembroke Pines'),

('Leonard','Cook','2000-09-14','8046 Maple St.','Highland Park'),

('William','Markham','1999-07-06','1600 Sylvan Ln.','Lake Forest'),

('Sam','Cook','1998-10-13','8046 Maple St.','Highland Park'),

('Fred','Williams','1999-07-08','722 Oack Knoll','Arlington'),

('Sally','Fillmore','2000-03-25','1215 Carrington St.','Decatur'),

('Mary','Jones','1999-11-13','1940 Grant St.','Denver'),

('Phyllis','Jones','1999-11-13','1940 Grant St.','Denver');

Solutions

Expert Solution

I am writing two parts of same problem in Sol a)  ans Sol b) . if Sol a) doesn't work then go for Sol b) in which there are two entries for the same pair of twins.

Sol a)

  • SQL > select * INTO new_table from ( SELECT s1.first_name as fname1, s2.first_name as fname2 FROM students as s1, students as s2 where s1.birthday=s2.birthday and s1.last_name=s2.last_name and s1.street_address=s2.street_address and s1.city=s2.city and s1.first_name != s2.first_name);
  • SQL > delete T from ( select row_number() over(order by [Timestamp]) as rn from new_table ) Twhere T.rn % 2 = 0

>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<

sol b)

SELECT s1.first_name as fname1, s2.first_name as fname2 FROM students as s1, students as s2 where s1.birthday=s2.birthday and s1.last_name=s2.last_name and s1.street_address=s2.street_address and s1.city=s2.city and s1.first_name != s2.first_name


Related Solutions

Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype,...
Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype, price] PROVIDER [pno, pname, web] SERVICE [dno, pno, servicedate] SERVICE.dno references DEVICE.dno SERVICE.pno references PROVIDER.pno bold is underline. a) Find the dno for the most expensive device b) Find all providers that have the work fast in the name c) Find the number of different device types (dtype) d) Give all details of devices with price more than $400
#Leadership Question Referring to Donald Trump, the president of the USA, answer the question below :...
#Leadership Question Referring to Donald Trump, the president of the USA, answer the question below : A. Using the attribution theory of leadership, discuss why people voted for Trump as the president of the USA B. Using the attribution theory of leadership, do you think he will be re-elected as US President? word limit- 200
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment...
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment 4’s schema (Customer-Invoice-Line-Product-Vendor). Make sure that your SQL script runs without any errors. Submit your answers in a .SQL file. 1 (2 Points) - Find the count of distinctvendors thatsupplied products that are priced lowerthan 185? 2 (2 Points) - For each vendor, find their product that has the lowest product quantity. Your output should include vendor code, vendor name, product description and product...
Leadership Subject Referring to Donald Trump, the president of the USA, answer the question below :...
Leadership Subject Referring to Donald Trump, the president of the USA, answer the question below : A.) Using the attribution theory, discuss why people voted for Trump as the president of the USA B.) Using the attribution theory, do you think he will be re-elected as US President? WORD LIMIT: 400 WORDS
Answer the following question using the table below. At what point does diminishing marginal utility set...
Answer the following question using the table below. At what point does diminishing marginal utility set in? If apples were freely given away at zero cost, how many apples would she choose to consume? Numbers of apples TU MU 1 7 7 2 13 6 3 18 5 4 22 4 5 25 3 6 27 2 7 28 1 8 28 0 9 27 -1 10 25 -2
SQL Question: What syntax to find the following? Out of the 10 employees, how many do...
SQL Question: What syntax to find the following? Out of the 10 employees, how many do we have a record of handling at least one order? You can do this by pulling the distinct employee ids from the Order table What syntax would you use to pull a list of all Shipper IDs and Names along with the count of all orders they’ve shipped? Make sure rename count(orders) to OrdersShipped. To do this you’ll need to join Orders and Shippers...
SQL Program True/False Question 1. Which of the following is true of a many to many...
SQL Program True/False Question 1. Which of the following is true of a many to many relationship? T/F 2. Security is rarely a concern for most databases. T/F 3. A security requirement refers to the need to restrict who can access some of the database data. T/F 4. Report requirements refer to the input forms the database will need. T/F 5. Insert permission is the permission to add records to the database. T/F 6. A trigger is code usually written...
USING SQL Create a table named Zones with the attributes and assumptions indicated below. Attributes: the...
USING SQL Create a table named Zones with the attributes and assumptions indicated below. Attributes: the zone ID, the lowest and the highest accepted temperature. Assumptions: the ID will be the primary key and have one or two digits, the temperatures (in Fahrenheit) will be at most two digits and a possible minus sign, none of the temperatures can be NULL. Populate table Zones so that it has the following rows: id lowerTemp higherTemp 2 -50 -40 3 -40 -30...
Answer the following questions by referring to the accompanying table, which lists the highway patrol’s reasons...
Answer the following questions by referring to the accompanying table, which lists the highway patrol’s reasons for stopping cars and the number of tickets issued. Reasons for stopping car Issued ticket Did not issue ticket Total Speeding 40 170 210 No taillights 10 35 45 Failure to use signals 5 25 30 Careless driving 45 70 115 TOTAL 100 300 400 Assume that a car was stopped. What is the probability that a ticket was issued? What is the probability...
answer the following question for oracle developer: 1- ____ is the category of SQL commands to...
answer the following question for oracle developer: 1- ____ is the category of SQL commands to create, alter or drop SQL objects (create a table, drop a view) 2-____ handles access to objects. The DBA might grant select on Customers to Bob. This will allow user Bob to read the Customers table. 3- Run this query in SQL Developer: Select sysdate from dual What is sysdate? What is dual? 4-What is a surrogate key? How are surrogate keys implemented in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT