03 Exp5 Abhishek
03 Exp5 Abhishek
Theory:
Table created.
Table created.
Q4. Insert values into the respective tables & display them
AVG(TFARE)
------------------
33625
SQL> select tikno,fare from ticket_details where fare=(select max(fare) from ticket_details);
TIKNO FARE
-------- ----------
25 800
30 800
SQL> select rid,rno,dist from route_header where dist=(select min(dist) from route_header);
SUM(FARE)
-----------------
2800
Q9. Give the total no of people who have travelled more than 36hrs.
Group by ticket no
SQL> select tikno,sum(adult+child) from ticket_header where ttime>=36 group by tikno;
TIKNO SUM(ADULT+CHILD)
---------- -----------------------------
12 50
25 60
48 40
TO_CHAR(SYSDATE,'DD
----------------------------------
26th march 2008
SQL pattern matching allows you to search for patterns in data if you don't know the exact word
or phrase you are seeking. This kind of SQL query uses wildcard characters to match a pattern,
rather than specifying it exactly. For example, you can use the wildcard "C%" to match any
string beginning with a capital C.
SELECT *
FROM employees
WHERE last_name LIKE 'C%'
SELECT *
FROM employees
WHERE last_name LIKE '%C%'
SELECT *
FROM employees
WHERE last_name LIKE '_ _C%'
• The % wildcard matches zero or more characters of any type and can be used to define
wildcards both before and after the pattern. If you're familiar with DOS pattern matching,
it's the equivalent of the * wildcard in that syntax.
• The _ wildcard matches exactly one character of any type. It's the equivalent of the ?
wildcard in DOS pattern matching.
• Specify a list of characters by enclosing them in square brackets. For example, the
wildcard [aeiou] matches any vowel.
• Specify a range of characters by enclosing the range in square brackets. For example, the
wildcard [a-m] matches any letter in the first half of the alphabet.
• Negate a range of characters by including the carat character immediately inside of the
opening square bracket. For example, [^aeiou] matches any non-vowel character while
[^am] matches any character not in the first half of the alphabet.
Combining Wildcards for Complex Patterns
Combine these wildcards in complex patterns to perform more advanced queries. For example,
suppose you need to construct a list of all of your employees who have names that begin with a
letter from the first half of the alphabet but do not end with a vowel. You could use the following
query:
SELECT *
FROM employees
WHERE last_name LIKE '[a-m]%[^aeiou]'
Similarly, you could construct a list of all employees with last names consisting of exactly four
characters by using four instances of the _ pattern:
SELECT *
FROM employees
WHERE last_name LIKE '____'
As you can tell, the use of SQL pattern matching capabilities offers database users the ability to
go beyond simple text queries and perform advanced searching operations.
Conclusion :- simple SQL queries, string manipulation operations are performed successfully.