CH1 Book Back
CH1 Book Back
NOTE:
ORDER BY: It is used to sort the records in ascending or descending order. If you
want to sort records in descending order use the desc keyword at the end of the Select
query.
HAVING: Having is used to restrict the result of the group by function rows according
to condition. It will work as same as where clause.
c. Site any two differences between Single_row functions and Aggregate functions.
Single row functions operate on a single row from the table at a time whereas aggregate
functions operate on a set of rows at a time.
Single row function display output for single row and display number rows whereas
aggregate functions display out as a single value from a set of rows.
Single row function can be used with select, where and order by clause whereas
aggregate functions can be only used with select clause.
Single row function examples are math, string and date/time functions. Aggregate
functions examples are ma, min, average, count etc.
Cartesian product refers to all possible pairs of rows from two relations.
It will just return a product of rows and the sum of columns from multiple relations
with or without common attributes.
Suppose two tables student and result have 6 and 8 rows as well as 4 and 5 columns
respectively. Then the cartesian product will return 48 rows and 9 columns as a result.
To display the day like “Monday”, “Tuesday” from the date when India got
independence.
dayname()
To display the specified number of characters from a particular position of the given
string.
substr(),mid()
monthname()
upper(),ucase()
o SELECT POW(2,3);
8
o SELECT ROUND(123.2345, 2), ROUND(342.9234,-1);
123.23 340
o SELECT LENGTH(“Informatics Practices”);
21
o SELECT YEAR(“1979/11/26”), MONTH(“1979/11/26”),
DAY(“1979/11/26”), MONTHNAME(“1979/11/26”);
1979 11 26 November
o SELECT LEFT(“INDIA”,3), RIGHT(“Computer Science”,4);
IND ence
o SELECT MID(“Informatics”,3,4), SUBSTR(“Practices”,3);
form actices
Create the table Product with appropriate data types and constraints.
Calculate the value of the discount in the table Product as 10 per cent
of the UPrice for all those products where the UPrice is more than
100, otherwise, the discount will be 0.
Manufacturer |
+--------------+
| Surf |
| Colgate |
| Lux |
| Pepsodant |
| Dove |
+--------------+
+-----------------------------+
| COUNT(DISTINCT PName) |
+-----------------------------+
| 4|
+----------------+-------------+-------------+
| PName | MAX(UPrice) | MIN(UPrice) |
+----------------+-------------+-------------+
| Washing Powder | 120 | 120 |
| Tooth Paste | 65 | 54 |
| Soap | 43 | 25 |
| Shampoo | 274 | 274 |
Set appropriate discount values for all cars keeping in mind the
following:
No discount is available on the LXI model.
A 12% discount is given on cars other than LXI model and VXI
model.
Display the name of the costliest car with fuel type “Petrol”.
StCode Stream
S01 Science
S02 Commerce
S03 Humanities
Create the table Student by choosing appropriate data types based on the
data given in the table.
Identify the Primary keys from tables Student and Stream. Also, identify
the foreign key from the table Stream.
Display the names of students whose names end with the character ‘a’.
Also, arrange the students in alphabetical order.
Mysql> select name from student where name like “%a” order by name;
Mysql> select name from student where stcode in(“S01”,”S03”) order by name,
admno;
List the number of students in each stream having more than 1 student.
mysql> Select stcode,count() From student Group by stcode Having count() >1;
Show the Cartesian product on the Student and Stream table. Also,
mention the degree and cardinality produced after applying the Cartesian
product.
The cartesian product on the student and stream table has degree of 5 and
cardinality of 18.