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
547 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 ==> | Calculations (18 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).
If you've reached this point, you're probably ready for a challenge. See if you can write a query to list out all of the non-boring events:
The first few of the 28 events you should see.
As the above query shows, a boring event is one which doesn't begin and end with the same letter, and which doesn't begin and end with a vowel!
If you get this working, you could always show that there aren't any ultra-interesting events (ones which begin and end in a vowel).
Save this query as Boring events, then close it down.
You can find other training resources for the subject of this exercise here:
From: | Bhavya59 |
When: | 31 Jul 24 at 11:57 |
SELECT [EventName]
,CASE
WHEN EventName LIKE '[AEIOUaeiou]%' AND EventName LIKE '%[AEIOUaeiou]' THEN 'begin and end with a vowel'
WHEN LEFT(EventName, 1) = RIGHT(EventName, 1) THEN 'Same Letter'
ELSE 'Boring events'
END
AS Verdict
FROM [WorldEvents].[dbo].[tblEvent]
From: | Devender |
When: | 17 Jan 24 at 06:05 |
select eventname,
case
when left(eventname,1) in ('a','e','i','o','u') and right (eventname , 1) in ('A','E','I','O','U')
THEN 'Begins and with Vowels'
when left(eventname,1) like right(eventname,1) then 'same letter'
end as 'Verdicts'
from tblEvent
where (case
when left(eventname,1) in ('a','e','i','o','u') and right (eventname , 1) in ('A','E','I','O','U')
THEN 'Begins and with Vowels'
when left(eventname,1) like right(eventname,1) then 'same letter'end ) is not null
From: | Yash2211 |
When: | 27 Aug 23 at 17:53 |
first I created view for simplicty then use logic,
/*Create view table1
as
select EventName,lower(left(eventname,1)) as lefty,lower(right(eventname,1)) as righty from tblEvent*/
select * from
(select eventname,
Case
when lefty=righty
then 'Same letter'
when righty in ('a','e','i','o','u') and lefty in ('a','e','i','o','u')
then 'Begin and ends with vowel'
end as 'verdict'
from table1) as t
where verdict is not null
From: | Chinmaykumar |
When: | 01 Jul 23 at 19:53 |
Query_Sol. for MySQL users
-- Important: in MySQL, '[]' wildcard do not work with LIKE function
-- used left(), right() function to extracts a number of characters from a string
SELECT EventName,
CASE
WHEN LEFT(EventName, 1) IN('A','E','I','O','U') AND RIGHT(EventName, 1) IN('a','e','i','o','u') THEN 'Begins and ends with vowels'
WHEN LEFT(EventName, 1) = RIGHT(EventName, 1) THEN 'Same letter'
END AS Verdict
FROM tblevent
HAVING Verdict IS NOT NULL
ORDER BY EventDate;
From: | zeephremiaa |
When: | 28 Sep 22 at 02:59 |
This works as well.
SELECT
EventName,
CASE
WHEN SUBSTRING(EventName, 1,1)=SUBSTRING(EventName, LEN(EventName)-0,LEN(EventName)-0) THEN 'SAME LETTER'
WHEN SUBSTRING(EventName, 1,1) IN ('A','E','I','O','U') AND SUBSTRING(EventName, LEN(EventName)-0,LEN(EventName)-0) IN ('A','E','I','O','U') THEN 'BEGINS AND END WITH A VOWEL'
END AS Verdict from tblEvent
WHERE
SUBSTRING(EventName, 1,1)=SUBSTRING(EventName, LEN(EventName)-0,LEN(EventName)-0) OR
(SUBSTRING(EventName, 1,1) IN ('A','E','I','O','U') AND SUBSTRING(EventName, LEN(EventName)-0,LEN(EventName)-0) IN ('A','E','I','O','U'))
ORDER BY EventDate ASC
From: | DbEnthusiast |
When: | 18 Dec 20 at 16:31 |
I think the following query should work too!
SELECT EventName
,CASE WHEN EventName LIKE '[AEIOU]%' AND EventName LIKE '%[aeiou]' THEN 'Begin and ends with vowel'
ELSE 'Same Letter' END AS Verdict
FROM tblEvent
Order BY Verdict
From: | SeahawkZim |
When: | 25 Nov 19 at 02:48 |
I added in the default of "Boring event" but this can be left out.
select EventName, case when left(eventname, 1) = right(eventname, 1) then 'Same letter'
when left(eventname, 1) like '[aeiou]' and right(eventname, 1) like '[aeiou]' then 'Begins and ends with a vowel'
else 'Boring event' end as Verdict
from tblevent
order by Verdict
From: | SeahawkZim |
When: | 30 Mar 22 at 00:35 |
I meant this:
select EventName, case when left(eventname, 1) = right(eventname, 1) then 'Same letter'
when left(eventname, 1) like '[aeiou]' and right(eventname, 1) like '[aeiou]' then 'Begins and ends with a vowel'
else 'Boring event' end as Verdict
from tblevent
WHERE case when left(eventname, 1) = right(eventname, 1) then 'Same letter'
when left(eventname, 1) like '[aeiou]' and right(eventname, 1) like '[aeiou]' then 'Begins and ends with a vowel'
else 'Boring event' end <> 'Boring event'
order by Verdict
From: | Habeshawiw2T |
When: | 12 Mar 19 at 15:13 |
SELECT * FROM (
SELECT EventName
, CASE
WHEN LOWER(LEFT(EventName,1)) IN ('a','e','i','o','u') AND LOWER(RIGHT(EventName,1)) IN ('a','e','i','o','u')
THEN 'Begins and ends with vowle'
WHEN LOWER(LEFT(EventName,1)) = LOWER(RIGHT(EventName,1))
THEN 'Same letter'
END AS Verdict
FROM tblEvent ) AS T
WHERE Verdict IS NOT NULL
From: | hjay629 |
When: | 19 Feb 19 at 01:01 |
NOTE: The QUESTION IS ORDERD BY EVENTDATE, if anyone was wondering the order.
If anyone could verify if this is correct, because it seem uncomfortably long:
SELECT
EventName,
CASE
WHEN LEFT(EventName, 1) = RIGHT(EventName, 1)
THEN 'Same letter'
WHEN (LEFT(EventName, 1) = 'a' OR LEFT(EventName, 1) = 'e' OR LEFT(EventName, 1) = 'i' OR LEFT(EventName, 1) = 'o' OR LEFT(EventName, 1) = 'u') AND (RIGHT(EventName, 1) = 'a' OR RIGHT(EventName, 1) = 'e' OR RIGHT(EventName, 1) = 'i' OR RIGHT(EventName, 1) = 'o' OR RIGHT(EventName, 1) = 'u')
THEN 'Begins and ends with vowel'
END as 'Verdict'
FROM
tblEvent
WHERE (CASE
WHEN LEFT(EventName, 1) = RIGHT(EventName, 1)
THEN 'Same letter'
WHEN (LEFT(EventName, 1) = 'a' OR LEFT(EventName, 1) = 'e' OR LEFT(EventName, 1) = 'i' OR LEFT(EventName, 1) = 'o' OR LEFT(EventName, 1) = 'u') AND (RIGHT(EventName, 1) = 'a' OR RIGHT(EventName, 1) = 'e' OR RIGHT(EventName, 1) = 'i' OR RIGHT(EventName, 1) = 'o' OR RIGHT(EventName, 1) = 'u')
THEN 'Begins and ends with vowel'
END ) IS NOT NULL
ORDER BY
EventDate
From: | tmccarthygcu |
When: | 06 Mar 19 at 20:08 |
Two ways to minimize the code. Firstly use an IN statement to have it group the sections without all those OR statements. To remove the lengthy WHERE clause, simply wrap up the SELECT in parens and name the result, then select all values from the result and do a WHERE on there, as seen here:
USE WorldEvents
SELECT t.* FROM (SELECT EventName,
CASE WHEN LEFT(EventName, 1) = RIGHT(EventName, 1)
THEN 'Same Letter'
WHEN LEFT(EventName, 1) IN ('a', 'e', 'i', 'o', 'u') AND RIGHT(EventName, 1) IN ('a', 'e', 'i', 'o', 'u')
THEN 'First letter vowel'
END AS 'Result'
FROM tblEvent) t
WHERE t.Result IS NOT NULL
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.