The Wise Owl logo (an owl and the company name)

Our training courses

Other training resources

Our training venues

Why we are different

Details for roqovzki

roqovzki has participated in the following threads:

Added by roqovzki on 12 Feb 2024 at 23:13

So, this is my pretty simple or maybe even dumb query (as I'm a beginner), but I came across this exercise and it seems to me that the solution given in the files and most of the users replies are incorrect.

I belivee most of the solutions miss out on one year of each century, as the century lasts from XX01-01-01 till XX00-12-31.
Let me know guys whether I'm completely missing on something.

SELECT

COUNT(*)

,CASE

WHEN EventDate BETWEEN '1701-01-01' AND '1800-12-31' THEN '18th century'

WHEN EventDate BETWEEN '1801-01-01' AND '1900-12-31' THEN '19th century'

WHEN EventDate BETWEEN '1901-01-01' AND '2000-12-31' THEN '20th century'

WHEN EventDate BETWEEN '2001-01-01' AND '2100-12-31' THEN '21th century'

END AS [Century]

FROM

tblEvent

GROUP BY CUBE

(CASE

WHEN EventDate BETWEEN '1701-01-01' AND '1800-12-31' THEN '18th century'

WHEN EventDate BETWEEN '1801-01-01' AND '1900-12-31' THEN '19th century'

WHEN EventDate BETWEEN '1901-01-01' AND '2000-12-31' THEN '20th century'

WHEN EventDate BETWEEN '2001-01-01' AND '2100-12-31' THEN '21th century'

END)


--------------------------------------------------------
WiseOwl query I believe should be like this:

SELECT

-- derive the century

CASE

WHEN year(e.EventDate) < 1801 THEN '18th century'

WHEN year(e.EventDate) < 1901 THEN '19th century'

WHEN year(e.EventDate) < 2001 THEN '20th century'

ELSE '21st century'

END AS Century,

COUNT(*) AS 'Number events'

FROM

tblEvent AS e

GROUP BY

-- need to group by the century too (the CUBE function shows the grand total too)

CUBE(

CASE

WHEN year(e.EventDate) < 1801 THEN '18th century'

WHEN year(e.EventDate) < 1901 THEN '19th century'

WHEN year(e.EventDate) < 2001 THEN '20th century'

ELSE '21st century'

END

)

ORDER BY

Century

Head office

Kingsmoor House

Railway Street

GLOSSOP

SK13 2AA

London

Landmark Offices

99 Bishopsgate

LONDON

EC2M 3XD

Manchester

Holiday Inn

25 Aytoun Street

MANCHESTER

M1 3AE

© Wise Owl Business Solutions Ltd 2025. All Rights Reserved.

End of small page here
Please be aware that our website uses cookies!
I'm OK with this Tell me more ...