Still working on SQL, but now trying to run some commands to pull data from the databases. The last 3 statements Im getting errors but I am not sure how to fix them. What do I need to do differently to those statements to make it work?
create table Employee(
EmpID char(10),
Name varchar2(50),
Salery char(10),
Address varchar2(50),
HireDate date,
Phone char(10),
Primary key(EmpID))
;
create table Inventory(
ProductID char(10),
ProductName varchar2(50),
UnitPrice char(10),
CurrentInventory char(10),
MonthlySales char(10),
PrecentOfPrice char(10),
Primary key(ProductID))
;
create table Transaction_(
TransactionID char(10),
TransactionCode varchar2(50),
Primary key(TransactionID))
;
create table Sales(
EmpID char(10),
ProductID char(10),
CustomerID char(10),
TransactionID char(10),
UnitsSold char(10),
PO# char(10),
SaleDate date,
Primary key(CustomerID),
Foreign key(EmpID) References Employee(EmpID),
Foreign key(ProductID) References Inventory(ProductID),
Foreign key(TransactionID) References Transaction_(TransactionID))
;
Insert into Employee values ('001','John Smith','35500','123 Main Street, Olympia WA','05-may-2018','1234567890')
;
Insert into Employee values ('002','Jane Doe','36000','259 Orange Ave, Olympia WA','16-sep-2018','2355695485')
;
Insert into Employee values ('003','Stan Lee','45000','958 State Street, Olympia WA','04-may-2016','1232344567')
;
Insert into Employee values ('004','Peter Snow','45250','259 Capital Way, Seattle WA','04-may-2016','9876543211')
;
Insert into Employee values ('005','Tony Stark','37500','599 Apple Way, Lacey WA','07-jul-2017','8795642312')
;
Insert into Inventory values ('010','Pride and Prejudice','15.99','56','12','50')
;
Insert into Inventory values ('011','Dune','17.75','48','8','65')
;
Insert into Inventory values ('012','Jurrasic Park','19.99','42','10','50')
;
Insert into Inventory values ('013','Target Hiroshima','21.99','12','2','45')
;
Insert into Inventory values ('014','One Second After','16.99','40','10','50')
;
Insert into Transaction_ values ('001','Cash')
;
Insert into Transaction_ values ('002','Credit')
;
Insert into Transaction_ values ('003','Check')
;
Insert into Sales values ('001','010','100','002','1','456123','08-jun-2019')
;
Insert into Sales values ('002','012','101','002','1','456124','09-may-2019')
;
Insert into Sales values ('003','011','102','001','1','456125','10-may-2019')
;
Insert into Sales values ('004','014','106','003','2','456126','02-jun-2019')
;
Insert into Sales values ('005','013','103','002','5','456127','03-jul-2019')
;
SELECT * from Employee;
SELECT * from Inventory;
SELECT * from Sales where SaleDate BETWEEN '09-may-2019' and '09-jun-2019';
SELECT "ProductID", sum (CurrentInventory-UnitsSold) from Inventory GROUP BY "ProductID
SELECT * from Sales, where EmpID is '002';
SELECT TOP 10 ProductID, SUM(UnitsSold) UnitsSold FROM Sales BETWEEN '09-may-2019' and '09-jun-2019';
If you have any doubts, please give me comment...
create table Employee(
EmpID char(10),
Name varchar2(50),
Salery char(10),
Address varchar2(50),
HireDate date,
Phone char(10),
Primary key(EmpID)
);
create table Inventory(
ProductID char(10),
ProductName varchar2(50),
UnitPrice char(10),
CurrentInventory char(10),
MonthlySales char(10),
PrecentOfPrice char(10),
Primary key(ProductID)
);
create table Transaction_(
TransactionID char(10),
TransactionCode varchar2(50),
Primary key(TransactionID)
);
create table Sales(
EmpID char(10),
ProductID char(10),
CustomerID char(10),
TransactionID char(10),
UnitsSold char(10),
PO# char(10),
SaleDate date,
Primary key(CustomerID),
Foreign key(EmpID) References Employee(EmpID),
Foreign key(ProductID) References Inventory(ProductID),
Foreign key(TransactionID) References Transaction_(TransactionID)
);
Insert into Employee values ('001','John Smith','35500','123 Main Street, Olympia WA','05-may-2018','1234567890');
Insert into Employee values ('002','Jane Doe','36000','259 Orange Ave, Olympia WA','16-sep-2018','2355695485');
Insert into Employee values ('003','Stan Lee','45000','958 State Street, Olympia WA','04-may-2016','1232344567');
Insert into Employee values ('004','Peter Snow','45250','259 Capital Way, Seattle WA','04-may-2016','9876543211');
Insert into Employee values ('005','Tony Stark','37500','599 Apple Way, Lacey WA','07-jul-2017','8795642312');
Insert into Inventory values ('010','Pride and Prejudice','15.99','56','12','50');
Insert into Inventory values ('011','Dune','17.75','48','8','65');
Insert into Inventory values ('012','Jurrasic Park','19.99','42','10','50');
Insert into Inventory values ('013','Target Hiroshima','21.99','12','2','45');
Insert into Inventory values ('014','One Second After','16.99','40','10','50');
Insert into Transaction_ values ('001','Cash');
Insert into Transaction_ values ('002','Credit');
Insert into Transaction_ values ('003','Check');
Insert into Sales values ('001','010','100','002','1','456123','08-jun-2019');
Insert into Sales values ('002','012','101','002','1','456124','09-may-2019');
Insert into Sales values ('003','011','102','001','1','456125','10-may-2019');
Insert into Sales values ('004','014','106','003','2','456126','02-jun-2019');
Insert into Sales values ('005','013','103','002','5','456127','03-jul-2019');
SELECT * from Employee;
SELECT * from Inventory;
SELECT * from Sales where SaleDate BETWEEN '09-may-2019' and '09-jun-2019';
SELECT ProductID, sum(CurrentInventory-UnitsSold) from Inventory GROUP BY ProductID;
SELECT * from Sales where EmpID = '002';
SELECT TOP 10 ProductID, SUM(UnitsSold) UnitsSold FROM Sales WHERE SaleDate BETWEEN '09-may-2019' and '09-jun-2019';
Still working on SQL, but now trying to run some commands to pull data from the...
write an SQL statement to list all the people in the Owner table, along with their pets' names if any. That is, for each pet an owner has, there will be a record containing the owner and the pet's name. For any owner contained in the Owner table, the output should always contain the owner's record even if no pets are associated with this owner. Hint: outer join/s may be needed. -- DROP TABLE PetAndOwner, Pet, PetType, Owner; CREATE TABLE...
MICROSOFT SQL SERVER - Create the following views 1.List the employee assigned to the most projects 2.List the project with the most hours SCRIPT TO BUILD DATABASE create table department ( dept_ID int not null , dept_name char(50) NOT NULL, manager_ID int not null, manager_start_date date not null, constraint Dept_PK primary key (dept_ID), constraint D_Name_AK unique (dept_name) ); insert into department values(1,'abc',1,'2019-01-08'); insert into department values(2,'abc2',2,'2019-01-08'); insert into department values(3,'abc3',2,'2019-01-08'); insert into department values(4,'abc4',2,'2019-01-08'); /*project table done*/ create table project...
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...
drop table department cascade constraints;
create table department (
Dname varchar2(15) not null,
Dnumber int not null,
Mgr_ssn char(9) not null,
mgr_start_date Date,
primary key (Dnumber),
Unique (Dname));
insert into DEPARTMENT values ('Research', '5', '333445555',
'22-May-1988');
insert into DEPARTMENT values ('Administration', '4', '987654321',
'01-Jan-1995');
insert into DEPARTMENT values ('Headquarters', '1', '888665555',
'19-Jun-1981');
drop table employee cascade constraints;
create table employee (
Fname varchar2(15) not null,
Minit char(1),
Lname varchar2(15) not null,
Ssn char(9),
Bdate date,
Address varchar2(30),
Sex char(1),...
/* I am executing following SQL statement for the below code but I am getting error. Pls, upload screenshot after running it. SQL Statement: SELECT OfferNo, CourseNo FROM Offering WHERE OfferTerm = 'Sum' AND OfferYear = 2012 AND FacSSN IS NULL; */ CREATE TABLE STUDENT( StdSSN INT NOT NULL PRIMARY KEY, StdFName VARCHAR2(50), StdLName VARCHAR2(50), StdCity VARCHAR2(50), StdState VARCHAR2(2), StdZip VARCHAR2(10), StdMajor VARCHAR2(15), StdYear VARCHAR2(20) ); CREATE TABLE FACULTY( FacSSN INTEGER NOT NULL PRIMARY KEY, FacFName VARCHAR(50), FacLName VARCHAR(50), FacCity...
An online company sells hundreds of office supply products on
its e-Commerce store. It has asked you to design and implement a
sales order processing system which will be used by users in our
Operations department to process sales orders. Here is an overview
of the sales order process. Customers make purchases by placing
orders. Each customer has a customer number and profile (such as
name, shipping address). To simplify the matter, each time an order
is placed, only one...
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...
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...
-- drop tables DROP TABLE REQUEST CASCADE CONSTRAINTS; DROP TABLE FULLORDER CASCADE CONSTRAINTS; DROP TABLE PRODUCT CASCADE CONSTRAINTS; DROP TABLE CUSTOMER CASCADE CONSTRAINTS; -- create and link tables CREATE TABLE CUSTOMER ( CustomerID INTEGER, Name VARCHAR2(40), City VARCHAR2(20), State CHAR(2), Zip CHAR(5), CONSTRAINT PK_CUSTOMER PRIMARY KEY (CustomerID) ); CREATE TABLE PRODUCT ( ProductID INTEGER, Description VARCHAR2(30), Material VARCHAR2(20), Price NUMBER(5,2), CONSTRAINT PK_PRODUCT...
-- drop tables DROP TABLE REQUEST CASCADE CONSTRAINTS; DROP TABLE FULLORDER CASCADE CONSTRAINTS; DROP TABLE PRODUCT CASCADE CONSTRAINTS; DROP TABLE CUSTOMER CASCADE CONSTRAINTS; -- create and link tables CREATE TABLE CUSTOMER ( CustomerID INTEGER, Name VARCHAR2(40), City VARCHAR2(20), State CHAR(2), Zip CHAR(5), CONSTRAINT PK_CUSTOMER PRIMARY KEY (CustomerID) ); CREATE TABLE PRODUCT ( ProductID INTEGER, Description VARCHAR2(30), Material VARCHAR2(20), Price NUMBER(5,2), CONSTRAINT PK_PRODUCT...