Question

In: Computer Science

1Write an SQL statement utilizing the WHERE, LIKE, and HAVING clauses that select gender, and the...

1Write an SQL statement utilizing the WHERE, LIKE, and HAVING clauses that select gender, and the email addresses that belong to female users and have an email address that contains a number (0 to 9) within it. Create an alias for the resultant email column name and name it ‘Email Addresses Female With Numbers’

  1. IPV4 (Internet Protocol Version 4) addresses utilize a notation known as the dotted-quad notation. Quad because an IPV4 address is actually a series of 4 numbers separated by a dot (hence dotted quad). Each one of the numbers has a range of 0-255. For example 255.0.65.23 is a valid IPV4 address, and so is 2.2.2.2. However, 2682.586.549.365 is NOT a valid IPV4 address (thank me later for not using IPV6 addresses for this – Google IPV6 and you will see what I mean).

    1. Write an SQL insert statement that will insert 4 rows with invalid IPV4 addresses.

    2. Write an SQL statement that will find all the rows with invalid IPV4 addresses.

      1. To do this you will need to utilize regular expressions. This is the research

        component of the lab.

      2. Regular expression documentation:

        https://dev.mysql.com/doc/refman/5.6/en/regexp.html

      3. You can look up the regular expression, you do not have to write one from scratch, but it is always a good thing to look up the syntax of regular expressions to be able to understand them.

      4. You need to validate that there are 4 numbers separated by dots each with a length of 1-3 (e.g., 999.999.999.999 is considered a valid IP address in your regular expression even though it is not in reality). Validating that there are 4 numbers separated by dots each with a length of 1-3 AND are less than 256 is a little complicated, but I encourage you to take on the challenge.

      5. By now you should see how the query from b can be created in a much cleaner fashion.

Solutions

Expert Solution

1.First create table profile using CREATE query

CREATE TABLE PROFILE(Name text, Gender text, Email varchar(50), IPV4 varchar(15));

2.Add values in table by using INSERT query

INSERT INTO PROFILE VALUES('Tom', 'Male', '[email protected]', '222.0.0.4');
INSERT INTO PROFILE VALUES('Tomi', 'Female', '[email protected]', '222.1.0.4');
INSERT INTO PROFILE VALUES('moni', 'Female', '[email protected]', '222.0.25.4');
INSERT INTO PROFILE VALUES('Tomu', 'Male', '[email protected]', '272.0.0.4');

3.Select values from table profile where gender is female with email containing digits using SELECT query
SELECT Gender, Email as 'Email Addresses Female With Numbers' FROM PROFILE WHERE Gender = 'Female' HAVING Email like '%[0-9]%' ;

4. Insert values in to table profile with invalid IP address

INSERT INTO PROFILE VALUES('Timi', 'Female', '[email protected]', '222.0.0.542');

INSERT INTO PROFILE VALUES('simi', 'Female', '[email protected]', '222.0.422.542');

INSERT INTO PROFILE VALUES('jimimi', 'Female', '[email protected]', '222.2222.0.542');

INSERT INTO PROFILE VALUES('aimi', 'Female', '[email protected]', '2232.0.0.542');

5. Select all rows which contains the invalid IP address using select query

select * from PROFILE where IPV4 check (ParseName(IPV4, 4) = BETWEEN 0 AND 255)
AND (ParseName(IPV4, 3) = BETWEEN 0 AND 255)
AND (ParseName(IPV4, 2) BETWEEN 0 AND 255)
AND (ParseName(IPV4, 1) BETWEEN 0 AND 255));


Related Solutions

Can you explain the means of “where, from, select”? Of SQL
Can you explain the means of “where, from, select”? Of SQL
MySQL: What are the various SELECT statement clauses? Which ones are necessary and optional? How are...
MySQL: What are the various SELECT statement clauses? Which ones are necessary and optional? How are the results filtered using COMPARISON and LOGICAL OPERATORS? Give one of these operators examples. Describe how parentheses can influence a query result.
QUESTION 26 For more efficient SQL, replace a series of OR clauses with IN AND NULL...
QUESTION 26 For more efficient SQL, replace a series of OR clauses with IN AND NULL DISTINCT 2.5 points    QUESTION 27 SELECT ADD_MONTHS('01-FEB_2016', 3) from dual; results in 04-FEB-2016 01-MAY-2016 31-MAY-2016 04-MAY-2016 2.5 points    QUESTION 28 joining a table to itself is refered to as an equijoin a self join an outer join a non equi-join 2.5 points    QUESTION 29 SELECT MIN(NAME) from Customer; will return which of the following rows ALICE WILLIAM BLAKE JAMAL 2.5 points...
Which of the following WHERE clauses could return the value “Ravnica” from the field SET? Select...
Which of the following WHERE clauses could return the value “Ravnica” from the field SET? Select one: a. WHERE SET = “Rav%”; b. WHERE SET LIKE “Rav_”; c. WHERE SET LIKE “%av”; d. WHERE SET LIKE “%R%i%”;
In SQL we are working with functions 1. Write a SELECT statement that returns these columns...
In SQL we are working with functions 1. Write a SELECT statement that returns these columns from the Instructors table: a. The AnnualSalary column b. A column named MonthlySalary that is the result of dividing the AnnualSalary column by 12 c. A column named MonthlySalaryRounded that calculates the monthly salary and then uses the ROUND function to round the result to 2 decimal places 2. Write a SELECT statement that returns these columns from the Students table: a. The EnrollmentDate...
Please implement this in Oracle sql 2.) Write a SELECT statement that answers this question: What...
Please implement this in Oracle sql 2.) Write a SELECT statement that answers this question: What is the total amount ordered for each product? Return these columns: The product name from the Products table The total amount for each product in the Order_Items (Hint: You can calculate the total amount by subtracting the discount amount from the item price and then multiplying it by the quantity) Use the ROLLUP operator to include a row that gives the grand total.
SQL injection works as follows A tool like sqlmap supplies a statement that is always true,...
SQL injection works as follows A tool like sqlmap supplies a statement that is always true, like 1=1, which tricks the web page into treating it like a human user rather than a robot. A tool like sqlmap supplies a statement that is always true, like 1=1, which tricks the database into upgrading the privileges from web user privileges to superuser privileges. The web user supplies an input string that contains the characters to close off an SQL statement and...
Consider the following SQL script. QUESTION: Which best completes the following statement(Select 3): Table SELECT TABLE...
Consider the following SQL script. QUESTION: Which best completes the following statement(Select 3): Table SELECT TABLE NAME is in SELECT NORMAL FORM and is SELECT FORM TYPE ***Note: The answer choices are at the bottom Assume also that even if there are some issues you cannot resolve them. Report on the current state of the database based on the code that you have been provided. CREATE TABLE ASSIGNMENT ( ASSIGN_NUM int, ASSIGN_DATE datetime, PROJ_NUM varchar(3), EMP_NUM varchar(3), ASSIGN_HOURS float(8), ASSIGN_CHG_HOUR...
Can you please implement this in Oracle sql Write a SELECT statement that returns one row...
Can you please implement this in Oracle sql Write a SELECT statement that returns one row for each customer that has orders with these columns: The email_address from the Customers table A count of the number of orders The total amount for each order (Hint: First, subtract the discount amount from the price. Then, multiply by the quantity.) Return only those rows where the customer has more than 1 order. Sort the result set in descending sequence by the sum...
How is having a third or alternative gender such as the Mahu gender different from cultural...
How is having a third or alternative gender such as the Mahu gender different from cultural understanding of binary male or female?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT