Question

In: Computer Science

This requirement can be met by using generic data, the correct mysql coding of script is...

This requirement can be met by using generic data, the correct mysql coding of script is more important than the data.

SQL scripts that return data from your database that has already had some processing done to it. Your task is to create these scripts that use built-in SQL functions to return the required data.

1. Create a query for the office table that returns the first 15 characters of the office name, the last two digits of the zip code, and all of the characters before the at sign "@" in the email address. All leading and trailing and trailing spaces must be removed and all data must be returned in upper case.

2. Create a query for the clients table that returns email address but add "mailto:" to the front of the email address, and returns the number of characters of the email address before adding "mailto:" in front of it. All leading and trailing and trailing spaces must be removed and all data must be returned in lower case.

3. Create a query for the listings table that returns listing price in whole dollars only without the cents. Also include the address, city, state, and zip code with each record in the result set. All leading and trailing and trailing spaces must be removed and all data must be returned in upper case.

4. Create a single query that returns the "current" day of the month, month, year, hour, minute, day of the week, quarter of the year, day of the year, and week of the year. Each item should be in a different column and the date must come from the system's clock and not hard coded.

5. Create a query for the contacts table that returns the number of days from the current system date and the "next contact date plus 30 days". Also include the client key and agent key for each record in the result set.

6. Create a query for the listings table that returns "Under $500,000" if the listing price is under $500,000 and "Over $500,000" if the listing price is $500,000 or more. Also include the address, city, state, and zip code with each record in the result set. All leading and trailing and trailing spaces must be removed and all data must be returned in upper case.

Solutions

Expert Solution

Answer 1:
SELECT UPPER(TRIM(SUBSTR(OfficeName,1, 15))), UPPER(TRIM(SUBSTR(ZipCode,-2))), UPPER(TRIM(SUBSTRING_INDEX(EmailAddress,'@',1))) FROM Office;

Answer 2:
SELECT LOWER(CONCAT('mailto:',TRIM(EmailAddress))), CHAR_LENGTH(EmailAddress) FROM clients;


Answer 3:
SELECT TRIM(SUBSTRING_INDEX(L.Price,',',1)) Price, UPPER(TRIM(C.Address)) Address, UPPER(TRIM(C.City)) City, UPPER(TRIM(C.State)) State, UPPER(TRIM(C.ZipCode)) ZipCode FROM Listings L JOIN Clients C on L.Id = C.Id;

Answer 4:
SELECT DAYOFMONTH(CURRENT_TIMESTAMP()) 'day of the month', MONTH(CURRENT_TIMESTAMP()) month, YEAR(CURRENT_TIMESTAMP()) year, HOUR(CURRENT_TIMESTAMP()) hour, MINUTE(CURRENT_TIMESTAMP()) minute,
DAYOFWEEK(CURRENT_TIMESTAMP()) 'day of the week', QUARTER(CURRENT_TIMESTAMP()) 'quarter of the year',
DAYOFYEAR(CURRENT_TIMESTAMP()) 'day of the year',WEEKOFYEAR(CURRENT_TIMESTAMP()) 'week of the year';

Answer 5:
SELECT DATEDIFF(CURDATE(), ADDDATE(ContactDate, INTERVAL 30 DAY)) as 'Number of Days' FROM Contacts C
JOIN Clients CL ON C.Clientkey = CL.Clientkey
JOIN Agents A ON C.AgentKey = A.AgentKey;

Answer 6:
SELECT IF(P.Price < 500,000, "Under $500,000", "Over $500,000") PriceRange, UPPER(TRIM(C.Address)) Address, UPPER(TRIM(C.City)) City, UPPER(TRIM(C.State)) State, UPPER(TRIM(C.ZipCode)) ZipCode FROM Listings L JOIN Clients C on L.Id = C.Id;



Related Solutions

This requirement can be met by using generic data, the correct mysql coding of script is...
This requirement can be met by using generic data, the correct mysql coding of script is more important than the data. 1. Increase all of the listing prices by 5% for all listings under $500,000 and 10% for all listings $500,000 and higher. Update the listings table with the new prices. 2. Add 30 days to the date expires for all listings. Update the listings table with the new prices. 3. Add "Listing updated on [current date]." to the remarks....
Using the sample.sql script, create the sample database in MySQL. Submit the MySQL interactive screen that...
Using the sample.sql script, create the sample database in MySQL. Submit the MySQL interactive screen that results. create database sample; use sample; create table customer (custno int auto_increment primary key, firstname varchar(20), middle varchar(20), lastname varchar(20), address varchar(60), telnum1 varchar(10), telnum2 varchar(10), telnum3 varchar(10), pin varchar(6), email varchar(30)); create table accttype (id int primary key, type varchar(10)); insert into accttype (id, type) values (1,'check'); insert into accttype (id, type) values (2,'save'); insert into accttype (id, type) values (3,'cd'); insert into...
This is in MySQL Part one: Using the MySQL Workbench Data Modeler, construct a diagram that...
This is in MySQL Part one: Using the MySQL Workbench Data Modeler, construct a diagram that shows the table in 3rd Normal Form. Part two: Provide a summary of the steps you took to achieve 3rd Normal form. Include your rationale for new table creation, key selection and grouping of attributes. Table Details: The Anita Wooten Art Gallery wishes to maintain data on their customers, artists and paintings. They may have several paintings by each artist in the gallery at...
coding the following project: Setting up structures to store and retrieve data. A major requirement of...
coding the following project: Setting up structures to store and retrieve data. A major requirement of virtually all projects in the financial world involves the storage and retrieval of data. project must be properly modularized and allow for more than one way to store the data to satisfy the various needs of clients.The first manner is by storing data using hashtables (or hash maps) as the basis of storing and retrieving data.
Solve using coding in R script: 1) Given a standard normal distribution, find the value of...
Solve using coding in R script: 1) Given a standard normal distribution, find the value of k such that P(Z < k) = 0.0197. 2) Given a normal distribution with mu = E(X) = 32 and sigma^2 = V(X) = 30, find the normal curve area to the left of x = 31. Report your code as well as your final answer (4 decimals). 3) A company pays its employees an average wage of $17.90 an hour with a standard...
Using PHP and MYSQL and with a simple customer database, how can I create a simple...
Using PHP and MYSQL and with a simple customer database, how can I create a simple log in and registration system for an ecommerce site
using PDO, MYSQL, and Html, how can i create a simple registration and login form for...
using PDO, MYSQL, and Html, how can i create a simple registration and login form for cPanel?
Data Structures and Algorithms Activity Requirement: Implement a queue using an array as its underline data...
Data Structures and Algorithms Activity Requirement: Implement a queue using an array as its underline data structure. Your queue should fully implemnted the following methods: first, push_back (enqueue), pop_front (dequeue), size, and isEmpty. Make sure to include a driver to test your newly implemented queue
National Correct Coding Initiative (CCI Edits)         INSTRUCTIONS: Review the following code pairs. Determine if you can...
National Correct Coding Initiative (CCI Edits)         INSTRUCTIONS: Review the following code pairs. Determine if you can bill together, assuming documentation supports it. If yes, which code is the second listed code? Make certain you add a modifier -59 to this code. Show exactly how you would bill the code(s). Code Pairs                                          Billable together (Y/N)                      How billed      94010 and 94060 93000 and 92953 30100 and 30200 30801 and 30130 44950 and 50020 50040 and 51702 59400 and 59414 10080 and 10081 12031 and...
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT