Вы находитесь на странице: 1из 42

Enter password: ****

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.5.46 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select * from employee;

ERROR 1046 (3D000): No database selected

mysql> use zensar;

Database changed

mysql> select * from employee;

+--------+----------+-------+---------+

| emp_id | emp_name | b_sal | dept_id |

+--------+----------+-------+---------+

| 1 | ron | 1000 | 543 |

| 2 | Elias | 2000 | 643 |

| 3 | Shane | 3000 | 743 |

+--------+----------+-------+---------+
3 rows in set (0.00 sec)

mysql> alter table employee add column DOB date;

Query OK, 3 rows affected (0.30 sec)

Records: 3 Duplicates: 0 Warnings: 0

mysql> alter table employee add column Hire date;

Query OK, 3 rows affected (0.60 sec)

Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from employee;

+--------+----------+-------+---------+------+------+

| emp_id | emp_name | b_sal | dept_id | DOB | Hire |

+--------+----------+-------+---------+------+------+

| 1 | ron | 1000 | 543 | NULL | NULL |

| 2 | Elias | 2000 | 643 | NULL | NULL |

| 3 | Shane | 3000 | 743 | NULL | NULL |

+--------+----------+-------+---------+------+------+

3 rows in set (0.00 sec)

mysql> insert into employee (DOB,Hire) values ('1-JAN-2000','15-MAR-2015');

ERROR 1292 (22007): Incorrect date value: '1-JAN-2000' for column 'DOB' at row 1

mysql> insert into employee (DOB,Hire) values ('2000-1-1','2015-5-15');

Query OK, 1 row affected (0.04 sec)


mysql> insert into employee (DOB,Hire) values ('1990-1-1','2000-5-15');

ERROR 1062 (23000): Duplicate entry '0' for key 'PRIMARY'

mysql> insert into employee (DOB,Hire) values ('1990-5-21','2001-7-20');

ERROR 1062 (23000): Duplicate entry '0' for key 'PRIMARY'

mysql> insert into employee (DOB,Hire) values ('1990-5-21','2001-7-20') where emp_id=1;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'where emp_id=1' at line 1

mysql> insert into employee (DOB,Hire) values ('1990-5-21','2001-7-20') where emp_id=2;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'where emp_id=2' at line 1

mysql> select current date;

ERROR 1054 (42S22): Unknown column 'current' in 'field list'

mysql> select current_date;

+--------------+

| current_date |

+--------------+

| 2019-06-06 |

+--------------+

1 row in set (0.02 sec)

mysql> desc new;

ERROR 1146 (42S02): Table 'zensar.new' doesn't exist

mysql> create table new(name varchar(10),DOB date,HD date);

Query OK, 0 rows affected (0.19 sec)

mysql> insert into new values ('Elias','2000-1-1','2015-5-15');


Query OK, 1 row affected (0.09 sec)

mysql> insert into new values ('ron','1990-5-21','2001-7-20');

Query OK, 1 row affected (0.09 sec)

mysql> select * from new;

+-------+------------+------------+

| name | DOB | HD |

+-------+------------+------------+

| Elias | 2000-01-01 | 2015-05-15 |

| ron | 1990-05-21 | 2001-07-20 |

+-------+------------+------------+

2 rows in set (0.00 sec)

mysql> select (current_date-HD)/12 from new;

+----------------------+

| (current_date-HD)/12 |

+----------------------+

| 3340.9166666666665 |

| 14990.5 |

+----------------------+

2 rows in set (0.09 sec)

mysql> select (current_date-HD)/12 as exp from new;

+--------------------+
| exp |

+--------------------+

| 3340.9166666666665 |

| 14990.5 |

+--------------------+

2 rows in set (0.01 sec)

mysql> select round(exp);

ERROR 1054 (42S22): Unknown column 'exp' in 'field list'

mysql> select round(exp) from new;

ERROR 1054 (42S22): Unknown column 'exp' in 'field list'

mysql> select round(current_date - HD/12) from new;

+-----------------------------+

| round(current_date - HD/12) |

+-----------------------------+

| 18511396 |

| 18523046 |

+-----------------------------+

2 rows in set (0.00 sec)

mysql> select round(current_date - HD)

-> ;

ERROR 1054 (42S22): Unknown column 'HD' in 'field list'

mysql> select (current_date-HD) as exp from new;

+--------+
| exp |

+--------+

| 40091 |

| 179886 |

+--------+

2 rows in set (0.00 sec)

mysql> select round((current_date - HD)/12) from new;

+-------------------------------+

| round((current_date - HD)/12) |

+-------------------------------+

| 3341 |

| 14990 |

+-------------------------------+

2 rows in set (0.02 sec)

mysql> select round((current_date - HD)/7) from new;

+------------------------------+

| round((current_date - HD)/7) |

+------------------------------+

| 5727 |

| 25698 |

+------------------------------+

2 rows in set (0.00 sec)


mysql> select (current_date - DOB) from new;

+----------------------+

| (current_date - DOB) |

+----------------------+

| 190505 |

| 290085 |

+----------------------+

2 rows in set (0.00 sec)

mysql> select (current_date - DOB)/12 from new;

+-------------------------+

| (current_date - DOB)/12 |

+-------------------------+

| 15875.416666666666 |

| 24173.75 |

+-------------------------+

2 rows in set (0.00 sec)

mysql> select getdate()-DOB from new;

ERROR 1305 (42000): FUNCTION zensar.getdate does not exist

mysql> select current_date-DOB from new;

+------------------+

| current_date-DOB |

+------------------+

| 190505 |
| 290085 |

+------------------+

2 rows in set (0.00 sec)

mysql> select current_date-[DOB] from new;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '[DOB] from new' at line 1

mysql> select datediff(yy,DOB,current_date) from new;

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'datediff'

mysql> select datediff(yy,DOB,getdate()) from new;

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'datediff'

mysql> select DATEDIFF(yy,DOB,getdate()) from new;

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'DATEDIFF'

mysql> select DATEDIFF(yy,'1980-4-4',getdate()) from new;

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'DATEDIFF'

mysql> select timestampdiff(year,'2000-12-12','2018-10-10');

+-----------------------------------------------+

| timestampdiff(year,'2000-12-12','2018-10-10') |

+-----------------------------------------------+

| 17 |

+-----------------------------------------------+

1 row in set (0.10 sec)

mysql> select timestampdiff(year,DOB,current_date);

ERROR 1054 (42S22): Unknown column 'DOB' in 'field list'

mysql> select timestampdiff(year,DOB,current_date) FROM new;


+--------------------------------------+

| timestampdiff(year,DOB,current_date) |

+--------------------------------------+

| 19 |

| 29 |

+--------------------------------------+

2 rows in set (0.00 sec)

mysql> select timestampdiff(year,DOB,getdate()) FROM new;

ERROR 1305 (42000): FUNCTION zensar.getdate does not exist

mysql> select timestampdiff(year,'2000-12-12','2018-12-12');

+-----------------------------------------------+

| timestampdiff(year,'2000-12-12','2018-12-12') |

+-----------------------------------------------+

| 18 |

+-----------------------------------------------+

1 row in set (0.00 sec)

mysql> select timestampdiff(month,'2000-12-12','2018-12-12');

+------------------------------------------------+

| timestampdiff(month,'2000-12-12','2018-12-12') |

+------------------------------------------------+

| 216 |

+------------------------------------------------+

1 row in set (0.00 sec)


mysql> select timestampdiff(days,'2000-12-12','2018-12-12');

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'days,'2000-12-12','2018-12-12')' at line 1

mysql> select timestampdiff(day,'2000-12-12','2018-12-12');

+----------------------------------------------+

| timestampdiff(day,'2000-12-12','2018-12-12') |

+----------------------------------------------+

| 6574 |

+----------------------------------------------+

1 row in set (0.00 sec)

mysql> select timestampdiff(year,'DOB',current_date) FROM new;

+----------------------------------------+

| timestampdiff(year,'DOB',current_date) |

+----------------------------------------+

| NULL |

| NULL |

+----------------------------------------+

2 rows in set, 2 warnings (0.00 sec)

mysql> select timestampdiff(year,(DOB),current_date) FROM new;

+----------------------------------------+

| timestampdiff(year,(DOB),current_date) |

+----------------------------------------+

| 19 |
| 29 |

+----------------------------------------+

2 rows in set (0.05 sec)

mysql> select * from new;

+-------+------------+------------+

| name | DOB | HD |

+-------+------------+------------+

| Elias | 2000-01-01 | 2015-05-15 |

| ron | 1990-05-21 | 2001-07-20 |

+-------+------------+------------+

2 rows in set (0.00 sec)

mysql> select timestampdiff(year,DOB,current_date) FROM new;

+--------------------------------------+

| timestampdiff(year,DOB,current_date) |

+--------------------------------------+

| 19 |

| 29 |

+--------------------------------------+

2 rows in set (0.00 sec)

mysql> select timestampdiff(month,DOB,current_date) FROM new;

+---------------------------------------+

| timestampdiff(month,DOB,current_date) |
+---------------------------------------+

| 233 |

| 348 |

+---------------------------------------+

2 rows in set (0.00 sec)

mysql> select timestampdiff(month,HD,CURRENT_DATE) FROM new;

+--------------------------------------+

| timestampdiff(month,HD,CURRENT_DATE) |

+--------------------------------------+

| 48 |

| 214 |

+--------------------------------------+

2 rows in set (0.00 sec)

mysql> select timestampdiff(YEAR,HD,CURRENT_DATE) FROM new;

+-------------------------------------+

| timestampdiff(YEAR,HD,CURRENT_DATE) |

+-------------------------------------+

| 4|

| 17 |

+-------------------------------------+

2 rows in set (0.00 sec)

mysql> select * from new;


+-------+------------+------------+

| name | DOB | HD |

+-------+------------+------------+

| Elias | 2000-01-01 | 2015-05-15 |

| ron | 1990-05-21 | 2001-07-20 |

+-------+------------+------------+

2 rows in set (0.00 sec)

mysql> select timestampdiff(YEAR,HD,CURRENT_DATE) FROM new;

+-------------------------------------+

| timestampdiff(YEAR,HD,CURRENT_DATE) |

+-------------------------------------+

| 4|

| 17 |

+-------------------------------------+

2 rows in set (0.00 sec)

mysql> update new set HD='2017-6-6' where name='ron';

Query OK, 1 row affected (0.12 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select timestampdiff(YEAR,HD,CURRENT_DATE) FROM new;

+-------------------------------------+

| timestampdiff(YEAR,HD,CURRENT_DATE) |

+-------------------------------------+
| 4|

| 2|

+-------------------------------------+

2 rows in set (0.00 sec)

mysql> select ROUND(timestampdiff(YEAR,HD,CURRENT_DATE) FROM new;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'FROM new' at line 1

mysql> select ROUND(timestampdiff(YEAR,HD,CURRENT_DATE)) FROM new;

+--------------------------------------------+

| ROUND(timestampdiff(YEAR,HD,CURRENT_DATE)) |

+--------------------------------------------+

| 4|

| 2|

+--------------------------------------------+

2 rows in set (0.00 sec)

mysql> select timestampdiff(YEAR,HD,CURRENT_DATE) FROM new;

+-------------------------------------+

| timestampdiff(YEAR,HD,CURRENT_DATE) |

+-------------------------------------+

| 4|

| 2|

+-------------------------------------+

2 rows in set (0.00 sec)


mysql> select * from new;

+-------+------------+------------+

| name | DOB | HD |

+-------+------------+------------+

| Elias | 2000-01-01 | 2015-05-15 |

| ron | 1990-05-21 | 2017-06-06 |

+-------+------------+------------+

2 rows in set (0.00 sec)

mysql> select timestampdiff(month,HD,CURRENT_DATE) FROM new;

+--------------------------------------+

| timestampdiff(month,HD,CURRENT_DATE) |

+--------------------------------------+

| 48 |

| 24 |

+--------------------------------------+

2 rows in set (0.00 sec)

mysql> update new set name=elias where name='Elias';

ERROR 1054 (42S22): Unknown column 'elias' in 'field list'

mysql> update new set name=elias where HD='2015-05-15;

'> update new set name=elias where HD='2015-05-15';

'> ;

'> update new set name=elias where HD='2015-05-15';

'> ;
'> update new set name=elias where HD='201

-> ;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '2015-05-15';

update new set name=elias where HD='2015-05-15';

update new set' at line 1

mysql> update new set name='elias' where HD='2015-05-15';

Query OK, 1 row affected (0.08 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from new;

+-------+------------+------------+

| name | DOB | HD |

+-------+------------+------------+

| elias | 2000-01-01 | 2015-05-15 |

| ron | 1990-05-21 | 2017-06-06 |

+-------+------------+------------+

2 rows in set (0.00 sec)

mysql> update new set name=CAP_FIRST(name);

ERROR 1305 (42000): FUNCTION zensar.CAP_FIRST does not exist

mysql> update new set name=capitalize(name);

ERROR 1305 (42000): FUNCTION zensar.capitalize does not exist

mysql> select UC_DELIMITER('ok',TRUE);


ERROR 1305 (42000): FUNCTION zensar.UC_DELIMITER does not exist

mysql> UPDATE test1 SET test_char = CONCAT(UCASE(LEFT(test_char, 1)), SUBSTRING(test_char, 2));

ERROR 1146 (42S02): Table 'zensar.test1' doesn't exist

mysql> update new set name=concat(ucase(left(name,1)),substring(name,2));

Query OK, 2 rows affected (0.10 sec)

Rows matched: 2 Changed: 2 Warnings: 0

mysql> select * from new;

+-------+------------+------------+

| name | DOB | HD |

+-------+------------+------------+

| Elias | 2000-01-01 | 2015-05-15 |

| Ron | 1990-05-21 | 2017-06-06 |

+-------+------------+------------+

2 rows in set (0.00 sec)

mysql> select getdate();

ERROR 1305 (42000): FUNCTION zensar.getdate does not exist

mysql> select' sysdate';

+----------+

| sysdate |

+----------+

| sysdate |

+----------+

1 row in set (0.00 sec)


mysql> select sysdate();

+---------------------+

| sysdate() |

+---------------------+

| 2019-06-06 07:04:02 |

+---------------------+

1 row in set (0.07 sec)

mysql> select * from new;

+-------+------------+------------+

| name | DOB | HD |

+-------+------------+------------+

| Elias | 2000-01-01 | 2015-05-15 |

| Ron | 1990-05-21 | 2017-06-06 |

+-------+------------+------------+

2 rows in set (0.00 sec)

mysql> alter table new add column sal int;

Query OK, 2 rows affected (0.32 sec)

Records: 2 Duplicates: 0 Warnings: 0

mysql> select * from new;

+-------+------------+------------+------+

| name | DOB | HD | sal |


+-------+------------+------------+------+

| Elias | 2000-01-01 | 2015-05-15 | NULL |

| Ron | 1990-05-21 | 2017-06-06 | NULL |

+-------+------------+------------+------+

2 rows in set (0.00 sec)

mysql> insert into new (name)values ('rohit');

Query OK, 1 row affected (0.08 sec)

mysql> insert into new (name)values ('akash');

Query OK, 1 row affected (0.08 sec)

mysql> select * from new;

+-------+------------+------------+------+

| name | DOB | HD | sal |

+-------+------------+------------+------+

| Elias | 2000-01-01 | 2015-05-15 | NULL |

| Ron | 1990-05-21 | 2017-06-06 | NULL |

| rohit | NULL | NULL | NULL |

| akash | NULL | NULL | NULL |

+-------+------------+------------+------+

4 rows in set (0.00 sec)

mysql> insert into new (sal)values (10000);

Query OK, 1 row affected (0.09 sec)


mysql> insert into new (sal)values (20000);

Query OK, 1 row affected (0.05 sec)

mysql> insert into new (sal)values (50000);

Query OK, 1 row affected (0.09 sec)

mysql> insert into new (sal)values (100000);

Query OK, 1 row affected (0.08 sec)

mysql> select * from new;

+-------+------------+------------+--------+

| name | DOB | HD | sal |

+-------+------------+------------+--------+

| Elias | 2000-01-01 | 2015-05-15 | NULL |

| Ron | 1990-05-21 | 2017-06-06 | NULL |

| rohit | NULL | NULL | NULL |

| akash | NULL | NULL | NULL |

| NULL | NULL | NULL | 10000 |

| NULL | NULL | NULL | 20000 |

| NULL | NULL | NULL | 50000 |

| NULL | NULL | NULL | 100000 |

+-------+------------+------------+--------+

8 rows in set (0.00 sec)


mysql> delete from new where sal=10000;

Query OK, 1 row affected (0.09 sec)

mysql> delete from new where sal=20000;

Query OK, 1 row affected (0.10 sec)

mysql> delete from new where sal=50000;

Query OK, 1 row affected (0.09 sec)

mysql> delete from new where sal=100000;

Query OK, 1 row affected (0.09 sec)

mysql> select * from new;

+-------+------------+------------+------+

| name | DOB | HD | sal |

+-------+------------+------------+------+

| Elias | 2000-01-01 | 2015-05-15 | NULL |

| Ron | 1990-05-21 | 2017-06-06 | NULL |

| rohit | NULL | NULL | NULL |

| akash | NULL | NULL | NULL |

+-------+------------+------------+------+

4 rows in set (0.00 sec)

mysql> insert into new (sal)values (10000) where name='Elias';

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'where name='Elias'' at line 1
mysql> update new set sal=10000 where name='Elias';

Query OK, 1 row affected (0.09 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> update new set sal=20000 where name='Ron';

Query OK, 1 row affected (0.09 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> update new set sal=50000 where name='rohit';

Query OK, 1 row affected (0.09 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> update new set sal=100000 where name='akash';

Query OK, 1 row affected (0.09 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from new;

+-------+------------+------------+--------+

| name | DOB | HD | sal |

+-------+------------+------------+--------+

| Elias | 2000-01-01 | 2015-05-15 | 10000 |

| Ron | 1990-05-21 | 2017-06-06 | 20000 |

| rohit | NULL | NULL | 50000 |

| akash | NULL | NULL | 100000 |

+-------+------------+------------+--------+
4 rows in set (0.00 sec)

mysql> alter table new add column d_id int;

Query OK, 4 rows affected (0.26 sec)

Records: 4 Duplicates: 0 Warnings: 0

mysql> update new set d_id=543 where name='Elias';

Query OK, 1 row affected (0.08 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> update new set d_id=112 where name='Ron';

Query OK, 1 row affected (0.09 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> update new set d_id=34 where name='rohit';

Query OK, 1 row affected (0.09 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> update new set d_id=56 where name='akash';

Query OK, 1 row affected (0.09 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from new;

+-------+------------+------------+--------+------+

| name | DOB | HD | sal | d_id |


+-------+------------+------------+--------+------+

| Elias | 2000-01-01 | 2015-05-15 | 10000 | 543 |

| Ron | 1990-05-21 | 2017-06-06 | 20000 | 112 |

| rohit | NULL | NULL | 50000 | 34 |

| akash | NULL | NULL | 100000 | 56 |

+-------+------------+------------+--------+------+

4 rows in set (0.00 sec)

mysql> select name from new group by sal;

+-------+

| name |

+-------+

| Elias |

| Ron |

| rohit |

| akash |

+-------+

4 rows in set (0.00 sec)

mysql> select name,sal from new group by sal;

+-------+--------+

| name | sal |

+-------+--------+

| Elias | 10000 |

| Ron | 20000 |
| rohit | 50000 |

| akash | 100000 |

+-------+--------+

4 rows in set (0.00 sec)

mysql> select avg(sal) from new where sal>avg(sal);;

ERROR 1111 (HY000): Invalid use of group function

ERROR:

No query specified

mysql> select avg(sal) from new where sal>avg(sal);

ERROR 1111 (HY000): Invalid use of group function

mysql> select sal from new where sal>avg(sal);

ERROR 1111 (HY000): Invalid use of group function

mysql> select sal from new group by d_id having sal>avg(sal);

Empty set (0.00 sec)

mysql> select sal,d_id from new group by d_id having sal>avg(sal);

Empty set (0.00 sec)

mysql> select sal,d_id from new group by d_id,sal having sal>avg(sal);

Empty set (0.00 sec)

mysql> select avg(sal) from new;

+------------+
| avg(sal) |

+------------+

| 45000.0000 |

+------------+

1 row in set (0.00 sec)

mysql> select sal from new where sal>avg(sal);

ERROR 1111 (HY000): Invalid use of group function

mysql> select sal from new group by d_id where sal>avg(sal);

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'where sal>avg(sal)' at line 1

mysql> select sal from new group by d_id where (sal>avg(sal));

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'where (sal>avg(sal))' at line 1

mysql> select sal from new group by sal where (sal>avg(sal));

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'where (sal>avg(sal))' at line 1

mysql> select sal from new group by sal where sal>avg(sal);

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'where sal>avg(sal)' at line 1

mysql> select sal from new group by sal where sal>avg(sal);

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'where sal>avg(sal)' at line 1

mysql> select d_id from new where sal>avg(sal);

ERROR 1111 (HY000): Invalid use of group function

mysql> select d_id from new group by d_id where sal>avg(sal);

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'where sal>avg(sal)' at line 1
mysql> select avg(sal),d_id from new group by d_id where sal>avg(sal);

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'where sal>avg(sal)' at line 1

mysql> select avg(sal),d_id from new group by d_id having sal>avg(sal);

ERROR 1054 (42S22): Unknown column 'sal' in 'having clause'

mysql> select sal,d_id from new group by d_id having sal>avg(sal);

Empty set (0.00 sec)

mysql> select avg(sal),d_id,sal

-> from new

-> group by d_id

-> having sal>avg(sal);

Empty set (0.00 sec)

mysql> select *from new;

+-------+------------+------------+--------+------+

| name | DOB | HD | sal | d_id |

+-------+------------+------------+--------+------+

| Elias | 2000-01-01 | 2015-05-15 | 10000 | 543 |

| Ron | 1990-05-21 | 2017-06-06 | 20000 | 112 |

| rohit | NULL | NULL | 50000 | 34 |

| akash | NULL | NULL | 100000 | 56 |

+-------+------------+------------+--------+------+

4 rows in set (0.00 sec)

mysql> update new set d_id=112 where name='Elias';


Query OK, 1 row affected (0.37 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> update new set d_id=56 where name='rohit';

Query OK, 1 row affected (0.09 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select *from new;

+-------+------------+------------+--------+------+

| name | DOB | HD | sal | d_id |

+-------+------------+------------+--------+------+

| Elias | 2000-01-01 | 2015-05-15 | 10000 | 112 |

| Ron | 1990-05-21 | 2017-06-06 | 20000 | 112 |

| rohit | NULL | NULL | 50000 | 56 |

| akash | NULL | NULL | 100000 | 56 |

+-------+------------+------------+--------+------+

4 rows in set (0.00 sec)

mysql> select avg(sal),d_id,sal

-> from new

-> group by d_id

-> having sal>avg(sal);

Empty set (0.00 sec)

mysql> select avg(sal),d_id from new group by d_id having sal>avg(sal);


ERROR 1054 (42S22): Unknown column 'sal' in 'having clause'

mysql> select avg(sal),sal,d_id from new group by d_id having sal>avg(sal);

Empty set (0.00 sec)

mysql> select max(avg(sal)) from new ;

ERROR 1111 (HY000): Invalid use of group function

mysql> select max(avg(sal)) from new SELECT MAX(avgsal) FROM (;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'SELECT MAX(avgsal) FROM (' at line 1

mysql> SELECT AVG(sal)) AS avgsal FROM employee GROUP BY deptno

-> ;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ') AS avgsal FROM employee GROUP BY deptno' at
line 1

mysql> SELECT MAX(avgsal) FROM (

-> SELECT AVG(sal)) AS avgsal FROM employee GROUP BY deptno

-> ) AS query1;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'FROM employee GROUP BY deptno

) AS query1' at line 2

mysql> select max(avg(sal)) from

-> (

-> select avg(sal)as avgsal from new group by d_id;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '' at line 3

mysql> select max(avg(sal)) from (select avg(sal) as avgsal from new group by d_id);

ERROR 1248 (42000): Every derived table must have its own alias
mysql> select max(avg(sal)) from (select avg(sal) as avgsal from new group by d_id) as q1;

ERROR 1054 (42S22): Unknown column 'sal' in 'field list'

mysql> select max(avg(sal)) from (select avg(sal),d_id as avgsal from new group by d_id) as q1;

ERROR 1054 (42S22): Unknown column 'sal' in 'field list'

mysql> select max(avg(sal)) from (select avg(sal),sal as avgsal from new group by d_id) as q1;

ERROR 1054 (42S22): Unknown column 'sal' in 'field list'

mysql> select max(avg(sal)) from (select sal,avg(sal) as avgsal from new group by d_id) as q1;

ERROR 1111 (HY000): Invalid use of group function

mysql> select max(avg(sal)),sal from (select avg(sal) as avgsal from new group by d_id) as q1;

ERROR 1054 (42S22): Unknown column 'sal' in 'field list'

mysql> select max(avg(sal))from (select avg(sal) as avgsal from new group by d_id) as q1 new;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'new' at line 1

mysql> select max(avg(sal))from (select avg(sal) from new group by d_id);

ERROR 1248 (42000): Every derived table must have its own alias

mysql> select max(avg(sal))from (select avg(sal) as avgsal from new group by d_id) as q1;

ERROR 1054 (42S22): Unknown column 'sal' in 'field list'

mysql> select sal,max(avg(sal))from (select avg(sal) as avgsal from new group by d_id) as q1;

ERROR 1054 (42S22): Unknown column 'sal' in 'field list'

mysql> select max(avg(sal))from (select avg(sal) as avgsal from new group by d_id) as q1;

ERROR 1054 (42S22): Unknown column 'sal' in 'field list'

mysql> select max(avg(sal))from (select avg(sal),d_id as avgsal from new group by d_id) as q1;

ERROR 1054 (42S22): Unknown column 'sal' in 'field list'

mysql> select avg(sal) from new group by d_id order by avg(sal) desc limit 1;

+------------+

| avg(sal) |
+------------+

| 75000.0000 |

+------------+

1 row in set (0.00 sec)

mysql> select avg(sal) from new group by d_id order by avg(sal) desc limit 2;

+------------+

| avg(sal) |

+------------+

| 75000.0000 |

| 15000.0000 |

+------------+

2 rows in set (0.00 sec)

mysql> select avg(sal) from new group by d_id order by avg(sal) desc limit 3;

+------------+

| avg(sal) |

+------------+

| 75000.0000 |

| 15000.0000 |

+------------+

2 rows in set (0.00 sec)

mysql> select avg(sal),d_id from new group by d_id order by avg(sal) desc limit 3;

+------------+------+
| avg(sal) | d_id |

+------------+------+

| 75000.0000 | 56 |

| 15000.0000 | 112 |

+------------+------+

2 rows in set (0.00 sec)

mysql> select avg(sal),d_id from new group by d_id order by avg(sal) desc limit 1;

+------------+------+

| avg(sal) | d_id |

+------------+------+

| 75000.0000 | 56 |

+------------+------+

1 row in set (0.00 sec)

Enter password: ****

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 19

Server version: 5.5.46 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select name from product

-> where

-> vname,vmob IN(

-> select vname,vmob from vendor where SP IN(

-> select SP from price group by v_id order by p_id));

ERROR 1046 (3D000): No database selected

mysql> use zensar;

Database changed

mysql> select name from product

-> where

-> vname,vmob IN(

-> select vname,vmob from vendor where SP IN(

-> select SP from price group by v_id order by p_id));

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'vmob IN(

select vname,vmob from vendor where SP IN(

select SP from price group ' at line 3

mysql> select name from product

-> where

-> vname,vmob =(

-> select vname,vmob from vendor where SP =(

-> select SP from price group by v_id order by p_id));

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'vmob =(

select vname,vmob from vendor where SP =(

select SP from price group by' at line 3

mysql> select a2.*

-> from

-> (select productcode, max(price) as m_price -- Swap this for min(price) for minimum

-> from vendor_price_list

-> group by productcode) a1

-> inner join vendor_price_list a2

-> on a2.productcode = a1.productcode

-> and a2.price = a1.m_price;

ERROR 1146 (42S02): Table 'zensar.vendor_price_list' doesn't exist

mysql> select vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price on


vendor.v_id=price.v_id group by vendor.vname order by lowest_price;

+-----------+--------------+

| vname | lowest_price |

+-----------+--------------+

| amzon | 200 |

| shopclues | 250 |

| ebay | 350 |

| flipcart | 700 |

+-----------+--------------+

4 rows in set (0.12 sec)

mysql> select product.name,vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price


on vendor.v_id=price.v_id group by vendor.vname order by lowest_price;
ERROR 1054 (42S22): Unknown column 'product.name' in 'field list'

mysql> select * from product;

+------+--------+

| p_id | name |

+------+--------+

| 1 | tees |

| 2 | mobile |

| 3 | books |

| 4 | TV |

| 5 | watch |

+------+--------+

5 rows in set (0.00 sec)

mysql> select * from vendor;

+------+-----------+--------+

| v_id | vname | vmob |

+------+-----------+--------+

| 10 | amzon | 992134 |

| 20 | shopclues | 435566 |

| 30 | flipcart | 762956 |

| 40 | ebay | 905466 |

+------+-----------+--------+

4 rows in set (0.00 sec)

mysql> select * from price;


+------+------+-------+

| p_id | v_id | SP |

+------+------+-------+

| 5 | 10 | 200 |

| 5 | 20 | 300 |

| 5 | 40 | 400 |

| 1 | 10 | 200 |

| 1 | 20 | 300 |

| 2 | 30 | 700 |

| 2 | 40 | 1000 |

| 3 | 20 | 250 |

| 3 | 40 | 350 |

| 4 | 10 | 30500 |

+------+------+-------+

10 rows in set (0.00 sec)

mysql> select product.name,vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price


on vendor.v_id=price.v_id group by product.name order by lowest_price;

ERROR 1054 (42S22): Unknown column 'product.name' in 'field list'

mysql> select product.name,vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price


on vendor.v_id=price.v_id group by product.name and vendor.vname order by lowest_price;

ERROR 1054 (42S22): Unknown column 'product.name' in 'field list'

mysql> select product.name,vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price


on vendor.v_id=price.v_id group by product.name,vendor.vname order by lowest_price;

ERROR 1054 (42S22): Unknown column 'product.name' in 'field list'

mysql> select product.name,vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price


on vendor.v_id=price.v_id group by product.name,vendor.vname order by lowest_price;
ERROR 1054 (42S22): Unknown column 'product.name' in 'field list'

mysql> select vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price on


vendor.v_id=price.v_id group by product.name,vendor.vname order by lowest_price;

ERROR 1054 (42S22): Unknown column 'product.name' in 'group statement'

mysql> select product.name,vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price


on vendor.v_id=price.v_id group by product,vname order by lowest_price;

ERROR 1054 (42S22): Unknown column 'product.name' in 'field list'

mysql> select vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price on


vendor.v_id=price.v_id group by product,vname order by lowest_price;

ERROR 1054 (42S22): Unknown column 'product' in 'group statement'

mysql> select vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price on


vendor.v_id=price.v_id group by vendor.vname order by lowest_price;

+-----------+--------------+

| vname | lowest_price |

+-----------+--------------+

| amzon | 200 |

| shopclues | 250 |

| ebay | 350 |

| flipcart | 700 |

+-----------+--------------+

4 rows in set (0.00 sec)

mysql> select vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price on


vendor.v_id=price.v_id group by vendor.vname,product.name order by lowest_price;

ERROR 1054 (42S22): Unknown column 'product.name' in 'group statement'

mysql> select vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price on


vendor.v_id=price.v_id group by vendor.vname,product.name order by lowest_price;

ERROR 1054 (42S22): Unknown column 'product.name' in 'group statement'


mysql> select vendor.vname,MIN(price.SP),product.name as lowest_price from vendor INNER JOIN price
on vendor.v_id=price.v_id INNER JOIN product on product.p_id=vendor.v_id group by
vendor.vname,product.name order by lowest_price;

Empty set (0.00 sec)

mysql> select vendor.vname,MIN(price.SP),product.name as lowest_price from vendor INNER JOIN price


on vendor.v_id=price.v_id INNER JOIN product on product.p_id=price.v_id group by
vendor.vname,product.name order by lowest_price;

Empty set (0.00 sec)

mysql> select vendor.vname,MIN(price.SP),product.name as lowest_price from vendor INNER JOIN price


on vendor.v_id=price.v_id INNER JOIN product on product.p_id=price.p_id group by
vendor.vname,product.name order by lowest_price;

+-----------+---------------+--------------+

| vname | MIN(price.SP) | lowest_price |

+-----------+---------------+--------------+

| shopclues | 250 | books |

| ebay | 350 | books |

| flipcart | 700 | mobile |

| ebay | 1000 | mobile |

| amzon | 200 | tees |

| shopclues | 300 | tees |

| amzon | 30500 | TV |

| amzon | 200 | watch |

| shopclues | 300 | watch |

| ebay | 400 | watch |

+-----------+---------------+--------------+

10 rows in set (0.00 sec)


mysql> select product.name,vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price
on vendor.v_id=price.v_id INNER JOIN product on product.p_id=price.p_id group by
vendor.vname,product.name order by lowest_price;

+--------+-----------+--------------+

| name | vname | lowest_price |

+--------+-----------+--------------+

| watch | amzon | 200 |

| tees | amzon | 200 |

| books | shopclues | 250 |

| watch | shopclues | 300 |

| tees | shopclues | 300 |

| books | ebay | 350 |

| watch | ebay | 400 |

| mobile | flipcart | 700 |

| mobile | ebay | 1000 |

| TV | amzon | 30500 |

+--------+-----------+--------------+

10 rows in set (0.00 sec)

mysql> select product.name,vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price


on vendor.v_id=price.v_id INNER JOIN product on product.p_id=price.p_id group by
product.name,vendor.vname order by lowest_price;

+--------+-----------+--------------+

| name | vname | lowest_price |

+--------+-----------+--------------+

| watch | amzon | 200 |


| tees | amzon | 200 |

| books | shopclues | 250 |

| watch | shopclues | 300 |

| tees | shopclues | 300 |

| books | ebay | 350 |

| watch | ebay | 400 |

| mobile | flipcart | 700 |

| mobile | ebay | 1000 |

| TV | amzon | 30500 |

+--------+-----------+--------------+

10 rows in set (0.00 sec)

mysql> select product.name,vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price


on vendor.v_id=price.v_id INNER JOIN product on product.p_id=price.p_id group by vendor.vname order
by lowest_price;

+--------+-----------+--------------+

| name | vname | lowest_price |

+--------+-----------+--------------+

| watch | amzon | 200 |

| watch | shopclues | 250 |

| watch | ebay | 350 |

| mobile | flipcart | 700 |

+--------+-----------+--------------+

4 rows in set (0.00 sec)

mysql> select product.name,vendor.vname,MIN(price.SP) as lowest_price from vendor INNER JOIN price


on vendor.v_id=price.v_id INNER JOIN product on product.p_id=price.p_id group by product.name order
by lowest_price;

+--------+-----------+--------------+

| name | vname | lowest_price |

+--------+-----------+--------------+

| watch | amzon | 200 |

| tees | amzon | 200 |

| books | shopclues | 250 |

| mobile | flipcart | 700 |

| TV | amzon | 30500 |

+--------+-----------+--------------+

5 rows in set (0.00 sec)

mysql> select product.name,vendor.vname,vendor.vmob ,MIN(price.SP) as lowest_price from vendor


INNER JOIN price on vendor.v_id=price.v_id INNER JOIN product on product.p_id=price.p_id group by
product.name order by lowest_price;

+--------+-----------+--------+--------------+

| name | vname | vmob | lowest_price |

+--------+-----------+--------+--------------+

| watch | amzon | 992134 | 200 |

| tees | amzon | 992134 | 200 |

| books | shopclues | 435566 | 250 |

| mobile | flipcart | 762956 | 700 |

| TV | amzon | 992134 | 30500 |

+--------+-----------+--------+--------------+

5 rows in set (0.00 sec)


mysql> select product.name,vendor.vname,vendor.vmob ,MIN(price.SP) as lowest_price from vendor
INNER JOIN price on vendor.v_id=price.v_id INNER JOIN product on product.p_id=price.p_id group by
product.name order by lowest_price;

Вам также может понравиться