Question

CREATE TABLE customer (    id INTEGER PRIMARY KEY,    customer_name TEXT,    contact_number TEXT );...

CREATE TABLE customer (

   id INTEGER PRIMARY KEY,

   customer_name TEXT,

   contact_number TEXT

);

CREATE TABLE supplier (

   id INTEGER PRIMARY KEY,

   supplier_name TEXT UNIQUE,

   contact_number TEXT

);

CREATE TABLE product (

   id INTEGER PRIMARY KEY,

   supplier_id INTEGER REFERENCES supplier(id),

   product_name TEXT,

   product_price INTEGER,

   UNIQUE(supplier_id, product_name)

);

CREATE TABLE purchase (

   id INTEGER PRIMARY KEY,

   customer_id INTEGER REFERENCES customer(id),

   purchase_date REAL,

   store_id INTEGER REFERENCES store(id)

);

CREATE TABLE store (

   id INTEGER PRIMARY KEY,

   store_name TEXT,

   store_address TEXT

);

CREATE TABLE purchase_product (

   purchase_id INTEGER REFERENCES purchase(id),

   product_id INTEGER REFERENCES product(id),

   quantity INTEGER

);

  1. List all ladders with multiple suppliers, along with the supplier that offers the lowest price for the given product.

  2. List the names of all customers who have purchased a product that could have been purchased from a supplier with a lower price by at least 5 dollars

    (500 cents), ordered by customer_name

  3. List all customers who have never made a purchase at the Diamond Drive

  4. List the names of all customers who purchased Tool 1717 and then later purchased O-Ring 1736, ordered by customer name.

  5. List the name and number of purchases made at each store, sorted by store name.

  6. List the name and total number of (non-distinct) items purchased at each store, sorted by store name.

  7. List the name and total number of (non-distinct) items purchased at each store, sorted by store name, after or on 2018-11-30.

  8. List the name and total number of (non-distinct) items purchased at each store, sorted by store name, for the months of October (before 2018-11-01), November (between 2018-11-01 and 2018-12-01), and December (after 2018-12-01). Your output should look like this, with ??? replaced with correct values:

    Los Alamos DD|October|???
    Los Alamos DD|November|???
    Los Alamos DD|December|???
    Los Alamos TD|October|???
    Los Alamos TD|November|???
    Los Alamos TD|December|???
    White Rock|October|???
    White Rock|November|???
    White Rock|December|???
    
0 0
Add a comment Improve this question Transcribed image text
Answer #1

List all ladders with multiple suppliers, along with the supplier that offers the lowest price for the given product.
Ans: Select supplier_name from supplier s join product p ON s.id = p.supplier_id where p.product_name ="xyz" order By p.product_price ASC

  
List all customers who have never made a purchase at the Diamond Drive

Ans: select c.customer_name from customer c JOIN purchase p on p.customer_id = c.id JOIN store s on s.id = p.store_id where s.store_name !="Diamond Drive"


    List the name and number of purchases made at each store, sorted by store name.
  
   ANS: Select s.store_name,count(p.id) from store s LEFT OUTER JOIN purchase p ON s.id = p.store_id GROUP BY s.id ORDER BY s.store_name ASC
  
  
    List the name and total number of (non-distinct) items purchased at each store, sorted by store name.
   ANS: please provide more info

    List the name and total number of (non-distinct) items purchased at each store, sorted by store name, after or on 2018-11-30.
   ANS: please provide more info

    List the name and total number of (non-distinct) items purchased at each store, sorted by store name, for the months of October (before 2018-11-01), November (between 2018-11-01 and 2018-12-01), and December (after 2018-12-01). Your output should look like this, with ??? replaced with correct values:
  
   ANS: please provide more info

  

Add a comment
Know the answer?
Add Answer to:
CREATE TABLE customer (    id INTEGER PRIMARY KEY,    customer_name TEXT,    contact_number TEXT );...
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
  • CREATE TABLE actor( id INTEGER NOT NULL, name VARCHAR(100), PRIMARY KEY (id) ); SELECT name FROM...

    CREATE TABLE actor( id INTEGER NOT NULL, name VARCHAR(100), PRIMARY KEY (id) ); SELECT name FROM actor WHERE name LIKE 'M%'; Q. How to run explain plan on the above query and display its output?

  • Consider the following table definitions: create table node (node_id integer primary key, node_color varchar(10)); create table...

    Consider the following table definitions: create table node (node_id integer primary key, node_color varchar(10)); create table edge (edge_id integer primary key, origin_id integer, destination_id integer, foreign key (origin_id) references node (node_id), foreign key (destination_id) references node (node_id) ); Which of the following list the ids of nodes that link to both the node with id 3 and and the node with id 4? select node id from node inner join edge on node_id=origin_id where destination_id=3 and destination_id=4; select node_id from...

  • CREATE TABLE Gender ( gender CHAR(1), description VARCHAR(10), PRIMARY KEY (gender) ); CREATE TABLE People (...

    CREATE TABLE Gender ( gender CHAR(1), description VARCHAR(10), PRIMARY KEY (gender) ); CREATE TABLE People ( ID INT, name VARCHAR(50), gender CHAR(1), height FLOAT, PRIMARY KEY (ID), FOREIGN KEY (gender) REFERENCES Gender (gender) ); CREATE TABLE Sports ( ID INT, name VARCHAR(50), record FLOAT, PRIMARY KEY (ID), UNIQUE (name) ); CREATE TABLE Competitions ( ID INT, place VARCHAR(50), held DATE, PRIMARY KEY (ID) ); CREATE TABLE Results ( peopleID INT NOT NULL, competitionID INT NOT NULL, sportID INT NOT NULL,...

  • CREATE TABLE person ( pid INTEGER NOT NULL ,pname VARCHAR(30) NOT NULL ,PRIMARY KEY (pid) );...

    CREATE TABLE person ( pid INTEGER NOT NULL ,pname VARCHAR(30) NOT NULL ,PRIMARY KEY (pid) ); CREATE TABLE organization ( oid INTEGER NOT NULL ,oname VARCHAR(30) NOT NULL ,PRIMARY KEY (oid) ); CREATE TABLE venue ( vid INTEGER NOT NULL ,area CHAR(1) NOT NULL ,capacity INTEGER NOT NULL ,PRIMARY KEY (vid) ); CREATE TABLE calendar ( vid INTEGER NOT NULL ,date DATE NOT NULL ,price NUMERIC(6,2) NOT NULL ,PRIMARY KEY(vid,date) ,FOREIGN KEY(vid) REFERENCES venue(vid) ); CREATE TABLE event ( eid...

  • The database(or the tables) are follow: CREATE TABLE employees ( id SERIAL NOT NULL PRIMARY KEY,...

    The database(or the tables) are follow: CREATE TABLE employees ( id SERIAL NOT NULL PRIMARY KEY, name TEXT NOT NULL, salary REAL NOT NULL DEFAULT 25000.0 ); CREATE TABLE employee_audit_log ( employee_id INTEGER NOT NULL, occurred_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); INSERT INTO employees(name, salary) VALUES ('Arnold Schwarznegger', 35000), ('Yuri Gargarin', 27000), ('Anakin Skywalker', 450000), ('Said Faroghi', 15000), ('Zino Holwerda', 8500); 1. Create a trigger for the employees table so that a new row is inserted in employee audit_log...

  • Given (Oracle) SQL Script " CREATE TABLE Members(    MemberID NUMBER(4) NOT NULL PRIMARY KEY,   ...

    Given (Oracle) SQL Script " CREATE TABLE Members(    MemberID NUMBER(4) NOT NULL PRIMARY KEY,    MFirst VARCHAR(25) NOT NULL,    MLast VARCHAR(25) NOT NULL,    Street VARCHAR(64) NOT NULL,    City VARCHAR(25) NOT NULL,    State VARCHAR(2) NOT NULL,    ZipCode NUMBER(5) NOT NULL,    CreditLimit NUMBER(7,2) NOT NULL,    Gender VARCHAR(1) NOT NULL CHECK (Gender IN('F','M')) ); CREATE TABLE Employees(    EmployeeID NUMBER(3) NOT NULL PRIMARY KEY,    EFirst VARCHAR(25) NOT NULL,    ELast VARCHAR(25) NOT NULL,   ...

  • -- Create a table with the following columns, named bsg_spaceship -- -- id - an auto-incrementing...

    -- Create a table with the following columns, named bsg_spaceship -- -- id - an auto-incrementing integer which is also the primary key -- name - variable-length string with a max of 255 characters, cannot be null -- separate_saucer_section - a boolean property which specifies whether or not there is a separate saucer section on the spaceship. This defaults to No. -- length - integer, cannot be null -- -- Once you have created the table, run the query "DESCRIBE...

  • create table candidate ( cand_id   varchar(12) primary key,   -- cand_id name       varchar(40)           --...

    create table candidate ( cand_id   varchar(12) primary key,   -- cand_id name       varchar(40)           -- cand_nm ); create table contributor ( contbr_id   integer primary key, name       varchar(40),           -- contbr_nm city     varchar(40),           -- contbr_city state       varchar(40),           -- contbr_st zip       varchar(20),           -- contbr_zip employer   varchar(60),           -- contbr_employer occupation   varchar(40)           -- contbr_occupation ); create table contribution ( contb_id   integer primary key, cand_id   varchar(12),           --...

  • SQL queries and procedures TABLE: Employees Business Rules: EmployeeID is defined as the primary key. Address...

    SQL queries and procedures TABLE: Employees Business Rules: EmployeeID is defined as the primary key. Address has been denormalized to include City and State for performance reasons. DeptNbr is a foreign key that references DeptNbr in the Department table Manager is a foreign key that references EmployeeID in the Employees table Data Structure: (EmployeeId, LastName, FirstName, Street, City, State, Zip, DateOfHire, DateOfBirth, JobTitle, Salary, DeptNbr(fk), Manager(fk)) TABLE: Department Business Rules: DeptNbr is defined as the primary key. Data Structure: (DeptNbr,...

  • Database Concepts! please help Consider the following create table statements: create table R (a integer primary...

    Database Concepts! please help Consider the following create table statements: create table R (a integer primary key); create tables (b integer primary key, c integer references R(a) on update cascade); Assume that these tables have the following data inserted: R: (1) and (2) S: (1,1) and (2, 1) What happens when we want to delete the record (1) from R? The corresponding record from S and T will be deleted due to the cascade option Only the record in Rwill...

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