Unformatted text preview: ERE R.bid = B.bid AND
R.sid= S.sid)); 42 Query Examples (continued) Query Examples (continued) String comparisons: (Q18) Find ages of sailors whose last name begins and ends with B
and has at least 3 characters. Can use comparison operators (=, <, >, etc.) to compare
WHERE Can also use LIKE operator as well as wild-card symbols.
0 or more arbitrary characters
exactly 1 character S.age
S.sname LIKE ‘B_%B’;
B_%B’ For example, ‘_AB%’ denotes a pattern matching any string
containing 3 or more characters, with the second and third
characters being AB. 43
43 Query Examples (continued) Query Examples (continued) (Q26) Find average age of sailors with a rating of 10.
WHERE (Q27) Find name and age of oldest sailor. AVG (S.age)
S.rating = 10; Solution with syntax error:
FROM (Q28) Count the number of sailors.
Sailors; 44 S.sname, MAX(S.age)
Sailors S; Correct solution: NOTE: No blank before “(”
with aggregate operators SELECT
WHERE (Q29) Count number of different sailor...
View Full Document
- Fall '12
- MYSQL , Foreign key, sailors, Sid