1. Write a query that finds all orders where the salesperson did not have an active training on the order date.   The following query seems to almost work, but pulls in order id 4 which does not meet criteria.   I believe there should be 5 results select * from orders t1 join training t2 on t1.salesperson_id = t2.salesperson_id where (order_date not between start_date and end_date or  order_date between start_date and end_date is null) group by id;   CREATE TABLE `training` ( `countID` smallint(6) NOT NULL AUTO_INCREMENT, `salesperson_id` varchar(30) DEFAULT NULL, `start_date` date DEFAULT NULL, `end_date` date DEFAULT NULL, PRIMARY KEY (`countID`)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

SQL

Sales people must be trained to make orders. For a sales person to receive credit for an order, the order_date must fall between a training start and end date for that sales person.

 

1. Write a query that finds all orders where the salesperson did not have an active training on the order date.

 

The following query seems to almost work, but pulls in order id 4 which does not meet criteria.

 

I believe there should be 5 results

select *

from orders t1

join training t2

on t1.salesperson_id = t2.salesperson_id

where (order_date not between start_date and end_date

or  order_date between start_date and end_date is null)

group by id;

 


CREATE TABLE `training` (
`countID` smallint(6) NOT NULL AUTO_INCREMENT,
`salesperson_id` varchar(30) DEFAULT NULL,
`start_date` date DEFAULT NULL,
`end_date` date DEFAULT NULL,
PRIMARY KEY (`countID`)
);

INSERT INTO `training` VALUES (1,'1','2012-01-01','2012-12-31'),(2,'1','2013-01-01',NULL),(3,'2','2012-01-01','2012-07-31'),(4,'2','2013-01-01','2013-05-01'),(5,'3','2012-01-01',NULL),(6,'4','2012-01-01','2012-12-31'),(7,'5','2013-01-01',NULL),(8,'6','2012-01-01',NULL);

CREATE TABLE `orders` (
`ID` smallint(6) NOT NULL AUTO_INCREMENT,
`order_date` varchar(30) DEFAULT NULL,
`salesperson_id` varchar(30) DEFAULT NULL,
`Amount` varchar(30) DEFAULT NULL,
PRIMARY KEY (`ID`)
);

INSERT INTO `orders` VALUES (1,'2012/08/02','2','540'),(2,'2012/1/30','4','1800'),(3,'2012/07/14','1','460'),(4,'2012/01/29','2','1100'),(5,'2013/02/03','6','600'),(6,'2013/03/02','4','1250'),(7,'2012/05/06','4','150'),(8,'2013/4/01','1','1000'),(9,'2013/03/05','2','950');

Expected Orders
in result
set
ID
order_date salesperson_id Amount
8/2/12
1
2
540
2
1/30/12
4
1800
3
7/14/12
1
460
1/29/12
2/3/13
4
2
1100
6
600
6
3/2/13
4
1250
7
5/6/12
14
150
4/1/13
3/5/13
8
1
1000
2
950
Training
田
ID
salesperson_id Start date End date
1/1/12
|1/1/13
|1/1/12
1/1/13
1/1/12
1
1
|12/31/12
2
1
NULL
3
2
7/31/12
4
2
5/1/13
5
NULL
4
1/1/12
12/31/12
6
7
5
1/1/13
NULL
8
1/1/12
NULL
Transcribed Image Text:Expected Orders in result set ID order_date salesperson_id Amount 8/2/12 1 2 540 2 1/30/12 4 1800 3 7/14/12 1 460 1/29/12 2/3/13 4 2 1100 6 600 6 3/2/13 4 1250 7 5/6/12 14 150 4/1/13 3/5/13 8 1 1000 2 950 Training 田 ID salesperson_id Start date End date 1/1/12 |1/1/13 |1/1/12 1/1/13 1/1/12 1 1 |12/31/12 2 1 NULL 3 2 7/31/12 4 2 5/1/13 5 NULL 4 1/1/12 12/31/12 6 7 5 1/1/13 NULL 8 1/1/12 NULL
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY