Question

In: Computer Science

1. How do I write a query that displays the name (concatenate the first name, middle...

1. How do I write a query that displays the name (concatenate the first name, middle initial, and last name), date of birth, and age for all students? Show the age with no decimal places, and only include those students who are 21 or older. Order by age, as shown below: (Hint: Use the TRUNC function. The ages may be different, depending on the date that the query is run.)

SELECT S_FIRST || ' ' || S_MI || ' ' || S_LAST AS "student name"
from STUDENT;

WHERE .....

Here is the query 1 result bellow

Full Name Date of birth Age

1. Brian D. Umato 1 9-AUG-98 21

2. Amanda J. Mobley 24-SEP- 96 22

3. Daniel . Black 10-OCT-94 24

Query 2. Employees table

Using the EMPLOYEES table, display the email, phone number, and then one other column (the name of the column is entered by the user). This same column is then also used in the ORDER BY clause to order the resulting rows. Restrict the rows to those that are equal to a certain department id (this number is also entered in by the user.) Use the double ampersand for the column substitution variable to insure that the user is prompted to enter the column name ONLY ONCE, and that it is “cleared out” after the run (UNDEFINE).

I just need a little solution thanks.

Solutions

Expert Solution

Question 1

Table Definition (DDL):

create table STUDENT
(
    FIRST_NAME     VARCHAR2(50),
    MIDDLE_INITIAL VARCHAR2(1),
    LAST_NAME      VARCHAR2(50),
    DATE_OF_BIRTH  DATE
)

Data:

Tom   K   Tommy   2015-09-18 00:00:00
Jerry   M   Jarr   1986-02-23 00:00:00
Chip   A   Che   2001-03-02 00:00:00
Donald   H   Duck   2002-11-11 00:00:00
Zorba   D   Greek   2000-10-01 00:00:00
Po   D   Panda   1995-08-30 00:00:00
Mulan   Z   Chan   1992-12-10 00:00:00

Query:

select first_name || ' ' || middle_initial || ' ' || last_name as full_name, date_of_birth, floor(months_between(trunc(sysdate), date_of_birth) / 12) as age
from student
order by age;

Result:

Tom K Tommy   2015-09-18 00:00:00   3
Donald H Duck   2002-11-11 00:00:00   16
Chip A Che   2001-03-02 00:00:00   18
Zorba D Greek   2000-10-01 00:00:00   18
Po D Panda   1995-08-30 00:00:00   24
Mulan Z Chan   1992-12-10 00:00:00   26
Jerry M Jarr   1986-02-23 00:00:00   33

Question 2
Table definition (DDL):
create table EMPLOYEES
(
    DEPT_ID    NUMBER,
    NAME  VARCHAR2(50),
    EMAIL VARCHAR2(50),
    PHONE VARCHAR2(20)
)

Data:

12   Jerome K Jerome   [email protected]   11235813
13   James Bond   [email protected]   12345678
9   Peter Pan   [email protected]   13579111
5   Harry Potter   [email protected]   24681012
11   Simba   [email protected]   12357111
15   Timon   [email protected]   24689101
8   Goofy   [email protected]   98765432
3   Aldous Huxley   [email protected]   87654321

Query:

select email, phone, &&dyna_col from employees order by &&dyna_col;

undefine dynacol;

undefine deptid;

Output:

SQL> select email, phone, &&dynacol from employees where dept_id = &&deptid order by &&dynacol;
Enter value for dynacol: name
Enter value for deptid: 15
old 1: select email, phone, &&dynacol from employees where dept_id = &&deptid order by &&dynacol
new 1: select email, phone, name from employees where dept_id = 15 order by name

EMAIL PHONE Name
------------------------------------------------------------------------------

[email protected]               24689101 Timon

Please provide feedback for the answer;


Related Solutions

How do I get the first initial of a first, middle, and last name? Also when...
How do I get the first initial of a first, middle, and last name? Also when I look to count characters in the name I want to be abel to count the spaces in-between the names how can i do this?
write a regular expression that will, using capturing groups, find: last name first name middle name...
write a regular expression that will, using capturing groups, find: last name first name middle name (if available) student ID rank home phone work phone (if available) email program (i.e., S4040) grade Replace the entire row with comma-delimited values in the following order: first name,middle name,last name,program,rank,grade,email,student ID,home phone,work phone Example substitution string for the first student Jane,V,Quinn,S4040,SO,B,[email protected],Q43-15-5883,318-377-4560,318-245-1144,Y
1. Write the SQL code required to list the employee number, first and last name, middle...
1. Write the SQL code required to list the employee number, first and last name, middle initial, and the hire date. Sort your selection by the hire date, to display the newly hired employees first. 2. Modify the previous query and list the employee first, last name and middle initial as one column with the title EMP_NAME. Make sure the names are listed in the following format: First name, space, initial, space, last name (e.g. John T Doe). Hint: use...
java programming write a program with arrays to ask the first name, last name, middle initial,...
java programming write a program with arrays to ask the first name, last name, middle initial, IDnumber and 3 test scores of 10 students. calculate the average of the 3 test scores. show the highest class average and the lowest class average. also show the average of the whole class. please use basic codes and arrays with loops the out put should look like this: sample output first name middle initial last name    ID    test score1 test score2...
Write the code in Java: 1. Create a method that displays your name in the console....
Write the code in Java: 1. Create a method that displays your name in the console. This method is void and takes no parameters. Make an app that runs the method in response to a button press. 2. Create a version of the method in #1 that takes the text (String) to be displayed as a parameter. Allow the user to enter the text in a dialog box or text field and display that text in the console. Be sure...
Write a query to return the date and day of the week of the first day...
Write a query to return the date and day of the week of the first day of the month two years from today. If today is 10/16/20, then the expect output is 10/01/2022 and the day of the week is thursday. I am using postgresql.
1. How do indexes improve SQL query performance? 2. How can stored procedure design improve query...
1. How do indexes improve SQL query performance? 2. How can stored procedure design improve query times in a data mart? 3. Why/How does de-normalization of a data mart design improve performance of queries? 4. What is a different between Client-Servervs. Distributed Architecture? 5. What are some primary features of a 3-tier architecture design?
Using the first code of this lab (Figure 1), write a code that displays the status...
Using the first code of this lab (Figure 1), write a code that displays the status of a push button on the LCD, that is, when you press it you should see “Pushed” on the LCD and when you release it, you should see “Released” #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2);...
Part 1 Write a program that displays a frame containing two labels that display your name,...
Part 1 Write a program that displays a frame containing two labels that display your name, one for your first name and one for your last. Experiment with the size of the window to see the labels change their orientation to each other. USE FIRST NAME: Aya LAST NAME: KAYED. SEND THE CODE IN THE EXACT FORMAT FOR JAVA ECLIPSE. I WILL COPY AND PASTE THE CODE SO I CAN RUN IT. Part 2 Propose and solve your own digital...
Please write the correct query for the following questions: Select the name of each manufacturer along...
Please write the correct query for the following questions: Select the name of each manufacturer along with the name and price of its most expensive product. Computer products are expensive. Find the maximum priced product. Which products are within $30 of the maximum priced product. Find the maker of the most expensive ‘drive’. Note, there are variety of drives in the data. Regular expressions help. Using the following table: CREATE TABLE manufacturers ( code number PRIMARY KEY NOT NULL, name...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT