Hi, I'm looking for the answer to these questions.
1. How many rows contained in table PERSON
2. How many rows contained in teble CAR
ONLY by reading information given. No DB's is needed!
Following table contain info about persons. Table do contain a lot of
rows!
CREATE TABLE Person
{
PersonID int NOT NULL IDENTITY(1,1)
PersNumber char(11) NOT NULL,
Name1 varchar(50) NOT NULL,
Name2 varchar(50) NOT NULL,
ShoeSize int NOT NULL,
Address varchar(50) NOT NULL,
Zip varchar(10) NOT NULL,
City varchar(50) NOT NULL
}
Further more, this table containg cars connected to persons in table
above.
CREATE TABLE Car
{
CarID int NOT NULL IDENTITY(1,1),
RegNr varchar(8) NOT NULL,
PersonID int NULL
}
Following SELECT statements are executed:
SELECT *
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
(1037854 rows is affected)
SELECT PersNumber, COUNT(*)
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
GROUP BY PersNumber
HAVING COUNT(*) > 1
(132892 rows are affected)
SELECT PersNumber, COUNT(*)
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
GROUP BY PersNumber
HAVING COUNT(*) > 2
(0 rows are affected)
SELECT COUNT(DISTINCT P. PersonID), COUNT (DISTINCT C.CarID)
FROM Person P FULL OUTER JOIN Car C ON P.PersonID = C.PersonID
WHERE C.CarID IS NULL OR P.PersonID IS NULL
-- --
198898 114388
(1 rows are affected)
Now...the answers.. GOOD LUCK!!! :)
1. How many rows contained in table PERSON
2. How many rows contained in teble CAR
Thanks to all gurus taking time solving this. Please, if you know this
- try to explain your solution!
Thanks again!!
/Markthere are 1037854 cars belonging to a person
SELECT *
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
(1037854 rows is affected)
and 114388 cars not belonging to anyone
total cars 1037854 + 114388
Similarly, there are (1037854 - 132892 - 0) persons having cars, and
198898 persons without cars
HIH
No comments:
Post a Comment