Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
544 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Software ==> | SQL (203 exercises) |
Topic ==> | Variables (11 exercises) |
Level ==> | Relatively easy |
Subject ==> | SQL training |
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
This will generate the database that you'll need to use in order to do this exercise (note that the database and script are only to be used for exercises published on this website, and may not be reused or distributed in any form without the prior written permission of Wise Owl).
The aim of this exercise is to summarise events using the MIN, MAX and COUNT functions:
The snag? You're not allowed to use GROUP BY!
To do this, create variables to hold each of the aggregates:
Variable | What it will hold eventually |
---|---|
@EarliestDate | The earliest date |
@LatestDate | The latest date |
@NumberOfEvents | The number of events |
@EventInfo | The title Summary of events |
Now use a single SELECT clause to set the value for all of these variables (alternatively you could use a series of subqueries).
Write another SELECT clause to show the value of the variables, to show the summary output shown above.
Optionally save this as The early, the late and the rest.sql and close it down.
You can find other training resources for the subject of this exercise here:
From: | Devender |
When: | 23 Jan 24 at 13:42 |
use WorldEvents
declare @EarliestDate date =
( select min(eventdate) from tblEvent)
declare @latestdate date = (
select max(eventdate) from tblEvent)
declare @NumberOfEvents int = (
select COUNT(*) from tblEvent e)
declare @EventInfo varchar(50)= 'Summary of events'
select
@EventInfo as 'tilte',
@EarliestDate as 'Earliset Date',
@LatestDate as 'Latest Date',
@NumberOfEvents as 'Number of Events'
From: | Drago |
When: | 09 May 23 at 21:25 |
declare @EventInfo varchar(25)= 'Summary of events'
declare @EarliestDate date =
(
select
MIN(e.EventDate)
from tblEvent e
)
declare @LatesttDate date =
(
select
Max(e.EventDate)
from tblEvent e
)
declare @NumberOfEvents int =
(
select
COUNT(*)
from tblEvent e
)
Select
@EventInfo as Title,
@EarliestDate as 'Earliset Date',
@LatesttDate as 'Latest Date',
@NumberOfEvents as 'Number of Events'
From: | akanksha1989 |
When: | 23 Nov 18 at 13:33 |
Hello.
I'm having trouble getting this exercise done.
Is there anywhere i can get the solution?
From: | shivendra |
When: | 16 Dec 18 at 07:26 |
use WorldEvents
declare @EarliestDate datetime
declare @latestDate datetime
declare @NoOfEvents int
declare @Eventimfo varchar(max)='Summary of event'
select @EarliestDate=min( cast(EventDate as date)) from dbo.tblEvent
select @latestDate=max(cast(EventDate as date)) from dbo.tblEvent
select @NoOfEvents=count(EventID) from dbo.tblEvent
select @Eventimfo as Title, @EarliestDate as EarliestDate,@latestDate as latestDate,@NoOfEvents as NoOfEvents
From: | Andy B |
When: | 23 Nov 18 at 15:12 |
We don't post the answers to exercises (as you'll have noticed) - partly because there has to be some reason to attend our courses, but also because it would remove the incentive to work at finding a solution. For the same reasons we usually don't post prospective answers, but since you ask nicely ... anyone out there able to help and post a solution?
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.