0% found this document useful (0 votes)
39 views

Assignment 1

The document shows the use of MySQL to create a database called "employee" and a table called "customer" with various columns. It then inserts 8 rows of data into the customer table. It performs several queries on the customer table to select, filter, order and group the data.

Uploaded by

SHIKHA BANSAL
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Assignment 1

The document shows the use of MySQL to create a database called "employee" and a table called "customer" with various columns. It then inserts 8 rows of data into the customer table. It performs several queries on the customer table to select, filter, order and group the data.

Uploaded by

SHIKHA BANSAL
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

mysql> show databases;

+--------------------+
| Database |
+--------------------+
| advik |
| employee |
| information_schema |
| mysql |
| performance_schema |
| school |
| sys |
+--------------------+
7 rows in set (0.00 sec)

mysql> use employee;


Database changed
mysql> create table customer(customer_id int,cust_name varchar(100),city
varchar(100),grade int,salesman_id int);
Query OK, 0 rows affected (0.05 sec)

mysql> insert into


customer(customer_id,cust_name,city,grade,salesman_id)values(3002,'Nick
Rimando','New York',100,5001);
Query OK, 1 row affected (0.01 sec)

mysql> insert into


customer(customer_id,cust_name,city,grade,salesman_id)values(3007,'Brad Davis','New
York',200,5001);
Query OK, 1 row affected (0.01 sec)

mysql> insert into


customer(customer_id,cust_name,city,grade,salesman_id)values(3005,'Graham
Zusi','California',200,5002);
Query OK, 1 row affected (0.00 sec)

mysql> insert into


customer(customer_id,cust_name,city,grade,salesman_id)values(3008,'Julian
Green','London',300,5002);
Query OK, 1 row affected (0.01 sec)

mysql> insert into


customer(customer_id,cust_name,city,grade,salesman_id)values(3004,'Fabian
Johnson','Paris',300,5006);
Query OK, 1 row affected (0.01 sec)

mysql> insert into


customer(customer_id,cust_name,city,grade,salesman_id)values(3009,'Geoff
Cameron','Berlin',100,5003);
Query OK, 1 row affected (0.01 sec)

mysql> insert into


customer(customer_id,cust_name,city,grade,salesman_id)values(3003,'Jozy
Altidor','Moscow',200,5007);
Query OK, 1 row affected (0.01 sec)

mysql> insert into


customer(customer_id,cust_name,city,grade,salesman_id)values(3001,'Brad
Guzan','London',100,5005);
Query OK, 1 row affected (0.01 sec)
mysql> select * from customer;
+-------------+----------------+------------+-------+-------------+
| customer_id | cust_name | city | grade | salesman_id |
+-------------+----------------+------------+-------+-------------+
| 3002 | Nick Rimando | New York | 100 | 5001 |
| 3007 | Brad Davis | New York | 200 | 5001 |
| 3005 | Graham Zusi | California | 200 | 5002 |
| 3008 | Julian Green | London | 300 | 5002 |
| 3004 | Fabian Johnson | Paris | 300 | 5006 |
| 3009 | Geoff Cameron | Berlin | 100 | 5003 |
| 3003 | Jozy Altidor | Moscow | 200 | 5007 |
| 3001 | Brad Guzan | London | 100 | 5005 |
+-------------+----------------+------------+-------+-------------+
8 rows in set (0.00 sec)

mysql> select customer_id,city from customer where salesman_id=5002;


+-------------+------------+
| customer_id | city |
+-------------+------------+
| 3005 | California |
| 3008 | London |
+-------------+------------+
2 rows in set (0.00 sec)

mysql> select customer_id,cust_name from customer where city='London';


+-------------+--------------+
| customer_id | cust_name |
+-------------+--------------+
| 3008 | Julian Green |
| 3001 | Brad Guzan |
+-------------+--------------+
2 rows in set (0.00 sec)

mysql> select cust_name,salesman_id from customer where grade>200;


+----------------+-------------+
| cust_name | salesman_id |
+----------------+-------------+
| Julian Green | 5002 |
| Fabian Johnson | 5006 |
+----------------+-------------+
2 rows in set (0.00 sec)

mysql> select * from customer where cust_name like('B%');


+-------------+------------+----------+-------+-------------+
| customer_id | cust_name | city | grade | salesman_id |
+-------------+------------+----------+-------+-------------+
| 3007 | Brad Davis | New York | 200 | 5001 |
| 3001 | Brad Guzan | London | 100 | 5005 |
+-------------+------------+----------+-------+-------------+
2 rows in set (0.00 sec)

mysql> select * from customer where salesman_id !=5006;


+-------------+---------------+------------+-------+-------------+
| customer_id | cust_name | city | grade | salesman_id |
+-------------+---------------+------------+-------+-------------+
| 3002 | Nick Rimando | New York | 100 | 5001 |
| 3007 | Brad Davis | New York | 200 | 5001 |
| 3005 | Graham Zusi | California | 200 | 5002 |
| 3008 | Julian Green | London | 300 | 5002 |
| 3009 | Geoff Cameron | Berlin | 100 | 5003 |
| 3003 | Jozy Altidor | Moscow | 200 | 5007 |
| 3001 | Brad Guzan | London | 100 | 5005 |
+-------------+---------------+------------+-------+-------------+
7 rows in set (0.00 sec)

mysql> select cust_name,city from customer where city='Paris';


+----------------+-------+
| cust_name | city |
+----------------+-------+
| Fabian Johnson | Paris |
+----------------+-------+
1 row in set (0.00 sec)

mysql> select DISTINCT(city) from customer;


+------------+
| city |
+------------+
| New York |
| California |
| London |
| Paris |
| Berlin |
| Moscow |
+------------+
6 rows in set (0.01 sec)

mysql> select * from customer order by cust_name asc;


+-------------+----------------+------------+-------+-------------+
| customer_id | cust_name | city | grade | salesman_id |
+-------------+----------------+------------+-------+-------------+
| 3007 | Brad Davis | New York | 200 | 5001 |
| 3001 | Brad Guzan | London | 100 | 5005 |
| 3004 | Fabian Johnson | Paris | 300 | 5006 |
| 3009 | Geoff Cameron | Berlin | 100 | 5003 |
| 3005 | Graham Zusi | California | 200 | 5002 |
| 3003 | Jozy Altidor | Moscow | 200 | 5007 |
| 3008 | Julian Green | London | 300 | 5002 |
| 3002 | Nick Rimando | New York | 100 | 5001 |
+-------------+----------------+------------+-------+-------------+
8 rows in set (0.00 sec)

mysql> select customer_id from customer order by customer_id asc;


+-------------+
| customer_id |
+-------------+
| 3001 |
| 3002 |
| 3003 |
| 3004 |
| 3005 |
| 3007 |
| 3008 |
| 3009 |
+-------------+
8 rows in set (0.00 sec)

You might also like