Question

I am using oracle sql developer to create some queries to generated reports and it is...

I am using oracle sql developer to create some queries to generated reports and it is not working.

I am not sure how to use count, group by, and order by.

Help me fix my query and explain to me how you did, so can do it next time.

Also, I have to convert this query to a stored procedure, so can you help me do it too?

Here is my query:

SELECT COUNT(GUEST.FIRSTNAME), GUEST.FIRSTNAME, GUEST.LASTNAME, GUEST.GUESTTYPE,

RESERVATION.RESERVATIONDATE, GUEST.EMAIL,

FROM (((GUEST

INNER JOIN ROOMRENTAL ON GUEST.GUESTID = ROOMRENTAL.GUESTID)

INNER JOIN DISABLEFRIENDLY ON ROOMRENTAL.ROOMID = DISABLEFRIENDLY.DFROOMID)

INNER JOIN RESERVATION ON GUEST.GUESTID = RESERVATION.GUESTID)

WHERE RESERVATION.RESERVATIONDATE >= '15-DEC-2018'

GROUP BY GUEST.GUESTID

ORDER BY GUEST.GUESTID;

===========================

============================

I UPDATED THE TABLES!

============================

============================

Here is the information required:

CREATE TABLE Guest

(

GuestID NUMBER(10) NOT NULL,

FirstName VARCHAR2(25) NOT NULL,

LastName VARCHAR2(25) NOT NULL,

NumberStreet VARCHAR2(25) NOT NULL,

City VARCHAR2(20) NOT NULL,

StateName VARCHAR2(20) NOT NULL,

ZipCode NUMBER(5) NOT NULL,

Country VARCHAR2(20) NOT NULL,

DateOfBirth DATE NOT NULL,

Age NUMBER(3) NOT NULL,

Gender VARCHAR2(1) NOT NULL,

MobileNumber NUMBER(10) NOT NULL,

Email CHAR(30) NULL,

GuestType VARCHAR2(10) NOT NULL,

CONSTRAINT GuestID_PK PRIMARY KEY (GuestID)

);

========================

========================

CREATE TABLE RoomRental

(

GuestID NUMBER (10) NOT NULL,

ReservationNumber NUMBER (10) NOT NULL,

RoomID NUMBER (10) NOT NULL,

CheckInDate DATE NOT NULL,

CheckInTime NUMBER (4) NOT NULL,

CheckOutDate DATE NOT NULL,

CheckOutTime NUMBER (4) NOT NULL,

CONSTRAINT G_R_R_PK PRIMARY KEY (GuestID, ReservationNumber, RoomID)

);

===========================

===========================

CREATE TABLE DisableFriendly

(

DFRoomID NUMBER (10) NOT NULL,

WheeledShowerChairAvailability VARCHAR2 (1) NOT NULL,

CONSTRAINT DFRoomID_PK PRIMARY KEY (DFRoomID)

);

=========================

=========================

CREATE TABLE Reservation

(

ReservationNumber Number(10) NOT NULL,

GuestID NUMBER(10) NOT NULL,

HotelID NUMBER(10) NOT NULL,

LocationID NUMBER(10) NOT NULL,

ReservationDate DATE NOT NULL,

DateIn DATE NOT NULL,

TimeIn NUMBER(4) NOT NULL,

DateOut DATE NOT NULL,

TimeOut NUMBER(4) NOT NULL,

NumberOfNights NUMBER(3) NOT NULL,

NumberOfRooms NUMBER(2) NOT NULL,

CONSTRAINT ReservationNumber_PK PRIMARY KEY (ReservationNumber)

);

=====================================

INSERT INTO Guest

(GuestID, FirstName, LastName, NumberStreet, City, StateName, ZipCode, Country,

DateOfBirth, Age, Gender, MobileNumber, Email, GuestType)

VALUES (5051003, 'Clark', 'Kent', '103 Orange Street', 'New York', 'New York', 10019, 'US',

TO_DATE('10-Nov-1971', 'DD-MON-YYYY'), 47, 'M', 2122200002, 'clarkkentmail.com', 'Corporate');

========================================

INSERT INTO RoomRental (GuestID, ReservationNumber, RoomID, CheckInDate, CheckInTime, CheckOutDate, CheckOutTime)

VALUES (5051003, 89981003, 80055001, TO_DATE('12-Apr-2019', 'DD-MON-YYYY'), 1500, TO_DATE('21-Apr-2019', 'DD-MON-YYYY'), 1100);

==========================================

INSERT INTO DisableFriendly (DFRoomID, WheeledShowerChairAvailability) VALUES (80055001, 'Y');

==========================================

INSERT INTO Reservation (ReservationNumber, GuestID, HotelID, LocationID, ReservationDate, DateIn,

TimeIn, DateOut, TimeOut, NumberOfNights, NumberOfRooms)

VALUES (89981003, 5051003, 70001, 9000700, TO_DATE('17-Dec-2018', 'DD-MON-YYYY'),

TO_DATE('17-Dec-2018', 'DD-MON-YYYY'), 1500, TO_DATE('19-Dec-2018', 'DD-MON-YYYY'), 1100, 2, 1);

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

SELECT T1.Total, T2.FIRSTNAME, T2.LASTNAME, T2.GUESTTYPE, T2.RESERVATIONDATE, T2.EMAIL
FROM (
SELECT COUNT(GUEST.FIRSTNAME) Total, GUEST.GUESTID AS GUESTID
FROM GUEST
GROUP BY GUEST.GUESTID ) T1
JOIN
(
SELECT GUEST.GUESTID AS GUESTID
   , GUEST.FIRSTNAME AS FIRSTNAME
   , GUEST.LASTNAME AS LASTNAME
   , GUEST.GUESTTYPE AS GUESTTYPE
   , RESERVATION.RESERVATIONDATE AS RESERVATIONDATE
   , GUEST.EMAIL AS EMAIL
FROM GUEST
INNER JOIN ROOMRENTAL
ON ( GUEST.GUESTID = ROOMRENTAL.GUESTID )
INNER JOIN DISABLEFRIENDLY
   ON ( ROOMRENTAL.ROOMID = DISABLEFRIENDLY.DFROOMID )
INNER JOIN RESERVATION
   ON ( GUEST.GUESTID = RESERVATION.GUESTID AND RESERVATION.RESERVATIONDATE >= '15-DEC-2018' )
) T2
ON (T1.GUESTID = T2.GUESTID)
ORDER BY T1.GUESTID;


ERROR :
[1] The previous query is incorrect because for group by function and other column in select query must include in group by column.
[2] The previous query in incomplete because opening and closing bracket are not properly

Solution
[1] Split previous query into 2 sub Query.
First Sub query get the count based on GUESTID group by.
   Second query remain same as previous on group by thing remove here.
[2] Join both the sub query using GUESTID and then order by them.

  

Add a comment
Know the answer?
Add Answer to:
I am using oracle sql developer to create some queries to generated reports and it is...
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
  • SQL: CREATE STATEMENT For patients whose last name matches the name entered by the user, display...

    SQL: CREATE STATEMENT For patients whose last name matches the name entered by the user, display their first name, phone number, and doctor's name. Note: Try Davis. (TEXT FOR DATABASE BELOW) DROP TABLE PATIENT; DROP TABLE BILLING; DROP TABLE DOCTOR; CREATE TABLE DOCTOR( DOC_ID VARCHAR2(10) NOT NULL, DOC_NAME VARCHAR2(20), DATEHIRED DATE, SALPERMON NUMBER(8), AREA VARCHAR2(20), SUPERVISOR_ID NUMBER(8), CHGPERAPPT NUMBER(8), ANNUAL_BONUS NUMBER(8), PRIMARY KEY (DOC_ID) ); INSERT INTO DOCTOR VALUES('432', 'Harrison', to_date('05-DEC-1994','dd-mon-yyyy'), 12000, 'Pediatrics', 100, 75, 4500); INSERT INTO DOCTOR VALUES('509',...

  • SQL - create statement for query For each patient, display his or her last name, first...

    SQL - create statement for query For each patient, display his or her last name, first name, and the name of his or her doctor. For each pediatrics patient, display his or her ID and his or her doctor's ID and name. For each doctor, display the name and the name of the doctor's supervisor in alphabetic order of supervisor's name. Include column aliases for clarity. Note: Check for accuracy. For each doctor in one of the two areas entered...

  • Oracle 12c SQL Chapter 12 Determine which orders were shipped to the same state as order...

    Oracle 12c SQL Chapter 12 Determine which orders were shipped to the same state as order 1014. CREATE TABLE Orders (Order# NUMBER(4), Customer# NUMBER(4), OrderDate DATE NOT NULL, ShipDate DATE, ShipStreet VARCHAR2(18), ShipCity VARCHAR2(15), ShipState VARCHAR2(2), ShipZip VARCHAR2(5), ShipCost NUMBER(4,2), CONSTRAINT orders_order#_pk PRIMARY KEY(order#), CONSTRAINT orders_customer#_fk FOREIGN KEY (customer#) REFERENCES customers(customer#)); INSERT INTO ORDERS VALUES (1000,1005,TO_DATE('31-MAR-09','DD-MON-YY'),TO_DATE('02-APR-09','DD-MON-YY'),'1201 ORANGE AVE', 'SEATTLE', 'WA', '98114' , 2.00); INSERT INTO ORDERS VALUES (1001,1010,TO_DATE('31-MAR-09','DD-MON-YY'),TO_DATE('01-APR-09','DD-MON-YY'), '114 EAST SAVANNAH', 'ATLANTA', 'GA', '30314', 3.00); INSERT INTO ORDERS VALUES (1002,1011,TO_DATE('31-MAR-09','DD-MON-YY'),TO_DATE('01-APR-09','DD-MON-YY'),'58...

  • Write a pl/sql block of code that will make a reservation for a customer for any...

    Write a pl/sql block of code that will make a reservation for a customer for any destination. The destination id, number of peolpe going and date will be entered by the user. Your code should calculate the cost and enter the data in the sales table. No destination can have more than 10 people going during the same dates. If the number is greater than 10 raise 'Sold_out' exception and print a message 'Sorry we are sold out for ths...

  • Q2. Retrieve the names of all employees from the employee table to produce output on CSV...

    Q2. Retrieve the names of all employees from the employee table to produce output on CSV format or delimited format with a common delimeter, rather than separete columns. Hint:Put the whole row into a string with a semicolon as the seperator(delimeter) between thecolumns: FORMAT:(fname;minit;lname) Example: EMPLOYEES -------------- James;E;Borg Frank;T;Wong Q3. Write a query to show the employees name from the employee table in this format: first letter of the first name, followed by a dot, a blank, and the full...

  • Query #2:       List the name of the project and total number of hours worked on by...

    Query #2:       List the name of the project and total number of hours worked on by all the employees on this project, also report the number of employees working on each project. Database: //STEP #1: CREATE TABLE employee ( fname varchar(15) not null, minit varchar(1), lname varchar(15) not null, ssn char(9), bdate date, address varchar(50), sex char, salary decimal(10,2), Super_ssn char(9), dno char(4), primary key (ssn)); CREATE TABLE department ( dname varchar(25) not null, dnumber char(4), Mgr_ssn char(9) not null,...

  • Oracle only database: DROP TABLE ORDERITEMS; DROP TABLE Orders; DROP TABLE BOOKAUTHOR; DRO...

    oracle only database: DROP TABLE ORDERITEMS; DROP TABLE Orders; DROP TABLE BOOKAUTHOR; DROP TABLE BOOKS; DROP TABLE PROMOTION; DROP TABLE AUTHOR; DROP TABLE CUSTOMERS; DROP TABLE PUBLISHER; CREATE TABLE Customers ( Customer# NUMBER(4), LastName VARCHAR2(10) NOT NULL, FirstName VARCHAR2(10) NOT NULL, Email VARCHAR(40), Address VARCHAR2(20), City VARCHAR2(12), State VARCHAR2(2), Zip VARCHAR2(5), Referred NUMBER(4), Region CHAR(2), CONSTRAINT customers_customer#_pk PRIMARY KEY(customer#) ); INSERT INTO CUSTOMERS VALUES (1001, 'MORALES', 'BONITA', '[email protected]', 'P.O. BOX 651', 'EASTPOINT', 'FL', '32328', NULL, 'SE'); INSERT INTO CUSTOMERS VALUES...

  • Provide the syntax answers for the following script, doesn't matter what table or columns. CREATE TABLE...

    Provide the syntax answers for the following script, doesn't matter what table or columns. CREATE TABLE customer (c_id NUMBER(5), c_last VARCHAR2(30), c_first VARCHAR2(30), c_mi CHAR(1), c_birthdate DATE, c_address VARCHAR2(30), c_city VARCHAR2(30), c_state CHAR(2), c_zip VARCHAR2(10), c_dphone VARCHAR2(10), c_ephone VARCHAR2(10), c_userid VARCHAR2(50), c_password VARCHAR2(15), CONSTRAINT customer_c_id_pk PRIMARY KEY (c_id)); CREATE TABLE order_source (os_id NUMBER(3), os_desc VARCHAR2(30), CONSTRAINT order_source_os_id_pk PRIMARY KEY(os_id)); CREATE TABLE orders (o_id NUMBER(8), o_date DATE, o_methpmt VARCHAR2(10), c_id NUMBER(5), os_id NUMBER(3), CONSTRAINT orders_o_id_pk PRIMARY KEY (o_id), CONSTRAINT orders_c_id_fk FOREIGN...

  • Query 1: Retrieve names of all the projects as well as First and Last name of...

    Query 1: Retrieve names of all the projects as well as First and Last name of managers if they are working on any of these projects. Database: //STEP #1: CREATE TABLE employee ( fname varchar(15) not null, minit varchar(1), lname varchar(15) not null, ssn char(9), bdate date, address varchar(50), sex char, salary decimal(10,2), Super_ssn char(9), dno char(4), primary key (ssn)); CREATE TABLE department ( dname varchar(25) not null, dnumber char(4), Mgr_ssn char(9) not null, Mgr_start_date date, primary key (dnumber)); CREATE...

  • I am using Oracle SQL and am new to it. I have seven tables, one of...

    I am using Oracle SQL and am new to it. I have seven tables, one of them is a subtable of two of the others. I need to do the following queries: 1. List all Patients and what Bed they are assigned to 2. List all patients who had Treatments and what Treatment they received 3. List all patients who had tests and what Test they had 4. List the employees (doctors, nurses, etc.) who assisted each patient. 5. List...

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