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
551 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 ==> | Aggregation and grouping (12 exercises) |
Level ==> | Harder than average |
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).
Create a query which shows two statistics for each category initial:
Here are the first few rows you should get when you run your ever-so-slightly contrived query:
It looks like most events begin with categories beginning with an E (there are 5 such categories, which helps), but that Ns have it for the longest average event name length.
You'll need to use the following functions at some point: CAST or CONVERT, AVG, COUNT, LEN, UPPER and LEFT!
Save this query as P please bob, then close it down.
You can find other training resources for the subject of this exercise here:
From: | Bhavya59 |
When: | 01 Aug 24 at 13:36 |
SELECT SUBSTRING(CategoryName, 1, 1) AS CategoryInitial
,COUNT(EventID) AS 'No of Events'
,AVG(CAST(LEN(EventName) AS DECIMAL(5,2))) 'Avg event name length'
FROM tblEvent e
INNER JOIN tblCategory c ON e.CategoryID=c.CategoryID
GROUP BY SUBSTRING(CategoryName, 1, 1)
From: | Rupchand7 |
When: | 14 Nov 23 at 06:44 |
select left(categoryname,1) as [Category initial], count(eventid) as [Number of events],
cast(avg(cast(len(eventname) as float)) as decimal(5,2)) as [Average event name length] from tblCategory join tblEvent on
tblCategory.CategoryID = tblEvent.CategoryID group by left(categoryname,1)
From: | Yash2211 |
When: | 03 Oct 23 at 16:36 |
select
left(tc.categoryname,1) as [Category intial],
count(te.eventid) as [No of Events],
cast(avg(cast(len(te.eventname) as float)) as decimal(6,2)) as [Average event name length]
from tblevent as te
inner join tblCategory tc on te.CategoryID=tc.CategoryID
group by left(tc.categoryname,1)
From: | FloridaMan |
When: | 24 Sep 21 at 15:52 |
select
left (c.CategoryName ,1) as Category_Initial
, count (e.EventName) as Number_of_Events
, sum(len (e.EventName)) as Total_Length
, cast(avg( cast( len (e.EventName) as float ) ) as decimal(6,2) ) as AVG_Event_Name_Length
from [dbo].[tblEvent] e
left join [dbo].[tblCategory] c
on e.CategoryID = c.CategoryID
group by left (c.CategoryName ,1)
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.