Friday, March 28, 2014

Pop Quiz

Well since I've spent a lot of time recently on the middle chapters of the book, I decided to review a couple old topics, hence the Pop Quiz title.  Just two questions:


1)  In Chapter 5 I had a question like this in the homework that I used from stack overflow:

USE TESTDB GO
CREATE TABLE chapter5 ( ID INT, Name VARCHAR(10));
USE TestDB
INSERT INTO chapter5 (ID, Name) VALUES (1, 'Alpha'), (2, 'Beta'), (3, 'Beta'), (4, 'Beta'), (5, 'Charlie'), (6, 'Charlie')

Here's the query itself
USE TestDB

SELECT NAME, COUNT(ID) AS idcoount
FROM chapter5
WHERE ID IS NOT NULL
GROUP BY Name
UNION ALL
SELECT 'SUM', COUNT(ID)
FROM chapter5

--
Explain why this invokes a conversion error:
USE TestDB
SELECT COUNT(ID) AS idcoount, Name
FROM chapter5
WHERE ID IS NOT NULL
GROUP BY Name
UNION ALL
SELECT 'SUM', COUNT(ID)
FROM chapter5

2)  Write a query that finds locations (region, and city) that are common (belong in both) between hr.employees and sales.customers using TSQL2012

That's all for now

No comments:

Post a Comment