Mysql Queries Exercises (Updated On 09-Jun)
Mysql Queries Exercises (Updated On 09-Jun)
Mysql Queries Exercises (Updated On 09-Jun)
+-------+--------+------+------------------+---------+
| regno | name | age | emailid | mobile |
+-------+--------+------+------------------+---------+
| 21001 | vijay | 13 | [email protected] | 8528197 |
| 21002 | krish | 13 | [email protected] | 9345644 |
| 21003 | akshay | 13 | [email protected] | 9543681 |
| 21004 | yadhav | 12 | [email protected] | 9274523 |
+-------+--------+------+------------------+---------+
4 rows in set (0.18 sec)
mysql> select * from stdrec group by tmarks order by tmarks desc limit 1,1;
+-------+-------+------+-----------------+---------+------------+--------+
| regno | name | age | emailid | mobile | doa | tmarks |
+-------+-------+------+-----------------+---------+------------+--------+
| 21001 | vijay | 13 | [email protected] | 8528197 | 2012-07-21 | 467 |
+-------+-------+------+-----------------+---------+------------+--------+
1 row in set (0.02 sec)
mysql> select * from stdrec group by tmarks order by tmarks desc limit 1,2;
+-------+-------+------+-----------------+---------+------------+--------+
| regno | name | age | emailid | mobile | doa | tmarks |
+-------+-------+------+-----------------+---------+------------+--------+
| 21001 | vijay | 13 | [email protected] | 8528197 | 2012-07-21 | 467 |
| 21002 | krish | 13 | [email protected] | 9345644 | 2014-03-22 | 380 |
+-------+-------+------+-----------------+---------+------------+--------+
2 rows in set (0.00 sec)
mysql> select * from stdrec group by tmarks order by tmarks desc limit 0,2;
+-------+--------+------+------------------+---------+------------+--------+
| regno | name | age | emailid | mobile | doa | tmarks |
+-------+--------+------+------------------+---------+------------+--------+
| 21004 | yadhav | 12 | [email protected] | 9274523 | 2017-02-19 | 500 |
| 21001 | vijay | 13 | [email protected] | 8528197 | 2012-07-21 | 467 |
+-------+--------+------+------------------+---------+------------+--------+
2 rows in set (0.00 sec)
mysql> select * from stdrec group by tmarks order by tmarks asc limit 1,1;
+-------+-------+------+-----------------+---------+------------+--------+
| regno | name | age | emailid | mobile | doa | tmarks |
+-------+-------+------+-----------------+---------+------------+--------+
| 21002 | krish | 13 | [email protected] | 9345644 | 2014-03-22 | 380 |
+-------+-------+------+-----------------+---------+------------+--------+
1 row in set (0.00 sec)
mysql> select * from stdrec group by tmarks order by tmarks asc limit 1,2;
+-------+-------+------+-----------------+---------+------------+--------+
| regno | name | age | emailid | mobile | doa | tmarks |
+-------+-------+------+-----------------+---------+------------+--------+
| 21002 | krish | 13 | [email protected] | 9345644 | 2014-03-22 | 380 |
| 21001 | vijay | 13 | [email protected] | 8528197 | 2012-07-21 | 467 |
+-------+-------+------+-----------------+---------+------------+--------+
2 rows in set (0.00 sec)
// Math functions
// Text functions
mysql> select * from stdrec where regno between 21002 and 21004;
+-------+--------+------+------------------+---------+------------+--------+
| regno | name | age | emailid | mobile | doa | tmarks |
+-------+--------+------+------------------+---------+------------+--------+
| 21002 | krish | 13 | [email protected] | 9345644 | 2014-03-22 | 380 |
| 21003 | akshay | 13 | [email protected] | 9543681 | 2013-08-10 | 320 |
| 21004 | yadhav | 12 | [email protected] | 9274523 | 2017-02-19 | 500 |
+-------+--------+------+------------------+---------+------------+--------+
3 rows in set (0.01 sec)
mysql> select * from stdrec where regno not between 21002 and 21004;
+-------+--------+------+-----------------+---------+------------+--------+
| regno | name | age | emailid | mobile | doa | tmarks |
+-------+--------+------+-----------------+---------+------------+--------+
| 21001 | vijay | 13 | [email protected] | 8528197 | 2012-07-21 | 467 |
| 21005 | Reshma | 14 | NULL | NULL | 2017-04-11 | 490 |
| 21001 | vijay | 12 | [email protected] | 8528197 | 2012-07-21 | 467 |
+-------+--------+------+-----------------+---------+------------+--------+
3 rows in set (0.00 sec)
//================TEXT FUNCTIONS=======================================
// ======= From table also we can make multiple data items as a single data item in
a resultant table.
SELECT CustomerName, CONCAT_WS(" ", Address, PostalCode, City) AS Address
FROM Customers;
//========Math functions================