Question

Consider the table actor which already exists in our database, with 200 rows. Upon executing SHOW...

Consider the table actor which already exists in our database, with 200 rows.

Upon executing SHOW CREATE TABLE `actor`, we get the following:

CREATE TABLE `actor` (
  `actor_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `first_name` varchar(10) NOT NULL,
  `last_name` varchar(10) NOT NULL,
  `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`actor_id`),
  KEY `idx_actor_last_name` (`last_name`)
 ) ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8

You will need this table for any questions below which refer to an `actor` table.

1.

Using the actor table described before, write a query to find out how many last_name start with each letter of the English alphabet. In the output, we want the number of actors whose name start with that letter, and the letter. You may omit those letters for which we don't have any last_name.

The function SUBSTRING might be useful to you. It's syntax is:

SUBSTRING(string,position,length)

It return a substring length characters long from string string, starting at position position.

Example:

substring('databases',1,4) will give you 'data'.

2.

From the actor table referred above, we want to find out the duplicate values of first_name among the actors, along with the count of how many actors share that first_name. We want only those records which were updated since the beginning of 2017.

The query that a student came up with is:

SELECT first_name, count(actor_id) FROM actor
GROUP BY first_name
HAVING count(actor_id) < 1
WHERE YEAR(last_update) >= 2006
AND MONTH(last_update) >= 1
AND DAY(last_update) >= 1

Will this query get us the results that we want?

If not, then what would be the correct query (provide the complete version)?

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

Hi
1.
select count(*), SUBSTRING(last_name,1,1) from actor group by SUBSTRING(last_name,1,1);
in the above query, first we group the results based on the first letter of the last name which is what is needed in question
2.

SELECT first_name, count(actor_id) FROM actor
GROUP BY first_name
HAVING count(actor_id) < 1
WHERE YEAR(last_update) >= 2006
AND MONTH(last_update) >= 1
AND DAY(last_update) >= 1

this query is wrong, first the date is wrong and next its printing values with count <1 the correct one is 


SELECT first_name, count(actor_id) FROM actor
GROUP BY first_name
HAVING count(actor_id) > 1  -- this will give same first names 
WHERE YEAR(last_update) >= 2017
AND MONTH(last_update) >= 1
AND DAY(last_update) >= 1



Thumbs up if this was helpful, otherwise let me know in comments

Add a comment
Know the answer?
Add Answer to:
Consider the table actor which already exists in our database, with 200 rows. Upon executing SHOW...
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
  • 0. Modify or create the table(file) named Staff first used in assignment 5. There is no...

    0. Modify or create the table(file) named Staff first used in assignment 5. There is no change to the structure, and if you need to recreate it the column names, data types and lengths are described below: Table Name Column Name Data Type Length Comment/constraint Staff: id int name varchar office char fee decimal reviewDate date 3 primary key 15 not null 7 7,2 default 0.00 Initials have been added to the name column values, so data for an insert...

  • PHP Programming In this project, you will create a Web page that allows visitors to your...

    PHP Programming In this project, you will create a Web page that allows visitors to your site to sign a guest book that is saved to a database. Create a new document in your text editor and type the <!DOCTYPE> declaration, <html> element, document head, and <body> element. Use the strict DTD and “Guest Book” as the content of the <title> element. Add the following text and elements to the document body: <h2>Enter your name to sign our guest book</h2>...

  • DROP TABLE IF EXISTS customers; DROP TABLE IF EXISTS orders; DROP TABLE IF EXISTS order_details; DROP...

    DROP TABLE IF EXISTS customers; DROP TABLE IF EXISTS orders; DROP TABLE IF EXISTS order_details; DROP TABLE IF EXISTS items; DROP TABLE IF EXISTS artists; DROP TABLE IF EXISTS employees; -- create tables CREATE TABLE customers (    customer_id INT ,    customer_first_name VARCHAR(20),    customer_last_name VARCHAR(20) NOT NULL,    customer_address VARCHAR(50) NOT NULL,    customer_city VARCHAR(20) NOT NULL,    customer_state CHAR(2) NOT NULL,    customer_zip CHAR(5) NOT NULL,    customer_phone CHAR(10) NOT NULL,    customer_fax CHAR(10),    CONSTRAINT customers_pk...

  • True or false? True or false? Question 63 Based on the Customer table below, which command...

    True or false? True or false? Question 63 Based on the Customer table below, which command lists all information from the table concerning customer 282? CustomerNum CustomerName --- Street City State Zip 148 Al's Appliance 28 Greenway Filmore FL 33336 282 Brookings 3827 Devon Grove FL 33321 Question 37 You have your project all set locally and on the server. You want to now make changes to your site. Which of the following is the last step of the process?...

  • You will develop an E-Commerce database used to maintain customers, products and sales information. You are...

    You will develop an E-Commerce database used to maintain customers, products and sales information. You are required to 1) gather and analyze requirements 2) design logical structure of the database 3) create stored procedures to develop the tables and insert the data 4) write SQL statements for data extraction and reporting. Throughout the course of this semester you have analyzed the requirements for an eCommerce database, designed and developed your database. As a class we have gone through the process...

  • How to write the insert, search, and remove functions for this hash table program? I'm stuck......

    How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...

  • Create a procedure to update the sales history table following the requirements below. A table creation...

    Create a procedure to update the sales history table following the requirements below. A table creation script is provided below. a) Call the procedure: UPDATE_SALES_HISTORY (The procedure name is important for our scripts to test and grade your code; please do not rename it (otherwise our scripts will not run and your score will be 0). b) The procedure takes 2 parameters: (4-digit-year, 2-digit-month). Both parameters will be numeric, e.g., (2019, 11) will denote 2019 (year) and November (month). The...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

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