Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
practicals
1
mysql> Show databases;
+--------------------+
| Database
|
+--------------------+
| information_schema |
| mysql
|
| performance_schema |
| test
|
+--------------------+
4 rows in set (0.00 sec)
2
mysql> Create database meangerie;
Query OK, 1 row affected (0.00 sec)
+-------------+---------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| productid | varchar(5) | YES |
| NULL |
|
| pname
| varchar(20) | YES |
| NULL |
|
| producttype | char(30)
| YES |
| NULL |
|
| productcost | decimal(10,0) | YES |
| NULL |
|
+-------------+---------------+------+-----+---------+-------+
8
mysql> Select char(65,67.3,69.3);
+--------------------+
| char(65,67.3,69.3) |
+--------------------+
| ACE
|
+--------------------+
1 row in set (0.00 sec)
9
mysql> INSERT INTO pet VALUES ('Puffball','Diane','hamster','f','1999-0330',NULL);
Query OK, 1 row affected (0.07 sec)
10
mysql> Select * from handbags;
+-----------+--------------+-------------+-------------+
| productid | pname
| producttype | productcost |
+-----------+--------------+-------------+-------------+
| 20000
| hidesign
| handbags |
13050 |
| 20001
| lavie
| handbag
|
15000 |
| 20002
| lara caren | clutches |
1200 |
| 20003
| baggit
| wallet
|
13460 |
| 24678
| phive rivers | clutches |
1670 |
| 24678
| 10th planets | wallet
|
15690 |
| 24679
| 3 mad chicks | handbags |
17890 |
+-----------+--------------+-------------+-------------+
7 rows in set (0.00 sec)
11
mysql> Select productid from handbags;
+-----------+
| productid |
+-----------+
| 20000
|
| 20001
|
| 20002
|
| 20003
|
| 24678
|
| 24678
|
| 24679
|
+-----------+
7 rows in set (0.00 sec)
12
mysql> select distinct producttype from handbags;
+-------------+
| producttype |
+-------------+
| handbags |
| handbag
|
| clutches |
| wallet
|
+-------------+
4 rows in set (0.05 sec)
13
mysql> Select all producttype from handbags;
+-------------+
| producttype |
+-------------+
| handbags |
| handbag
|
| clutches |
| wallet
|
| clutches |
| wallet
|
| handbags |
+-------------+
7 rows in set (0.00 sec)
14
17
mysql> Select pname,productcost from handbags where productcost<5000;
+--------------+-------------+
| pname
| productcost |
+--------------+-------------+
| lara caren |
1200 |
| phive rivers |
1670 |
+--------------+-------------+
2 rows in set (0.22 sec)
18
mysql> Select pname,producttype from handbags
where(producttype='handbags'or producttype='clutches');
+--------------+-------------+
| pname
| producttype |
+--------------+-------------+
| hidesign
| handbags |
| lara caren | clutches |
| phive rivers | clutches |
| 3 mad chicks | handbags |
+--------------+-------------+
4 rows in set (0.04 sec)
19
+--------------+
| productname |
+--------------+
| HIDESIGN
|
| LAVIE
|
| LARA CAREN |
| BAGGIT
|
| PHIVE RIVERS |
| 10TH PLANETS |
| 3 MAD CHICKS |
+--------------+
7 rows in set (0.00 sec)
22
mysql> Select substr('abcdefg',3,4)"subs";
+------+
| subs |
+------+
| cdef |
+------+
1 row in set (0.00 sec)
23
mysql> Select trim(leading'x' from 'xxxxbar one xxxx');
+------------------------------------------+
| trim(leading'x' from 'xxxxbar one xxxx') |
+------------------------------------------+
| bar one xxxx
|
+------------------------------------------+
1 row in set (0.05 sec)
24
mysql> Select trim(both'x' from 'xxxxbar one xxxx');
+---------------------------------------+
| trim(both'x' from 'xxxxbar one xxxx') |
+---------------------------------------+
| bar one
|
+---------------------------------------+
1 row in set (0.00 sec)
25
26
mysql> Select producttype,instr(pname,'ie')as "ie in product type" from
handbags;
+-------------+--------------------+
| producttype | ie in product type |
+-------------+--------------------+
| handbags |
0|
| handbag
|
4|
| clutches |
0|
| wallet
|
0|
| clutches |
0|
| wallet
|
0|
| handbags |
0|
+-------------+--------------------+
7 rows in set (0.02 sec)
27
mysql> Select length('candidate')"length in character";
+---------------------+
| length in character |
+---------------------+
|
9|
+---------------------+
1 row in set (0.00 sec)
28
mysql> Select left('uss/23/67/09',3);
+------------------------+
| left('uss/23/67/09',3) |
+------------------------+
| uss
|
+------------------------+
1 row in set (0.00 sec)
29
mysql> Select right('uss/23/67/09',3);
+-------------------------+
| right('uss/23/67/09',3) |
+-------------------------+
| /09
|
+-------------------------+
1 row in set (0.00 sec)
30
mysql> Select mid('Quadratically',5,6);
+--------------------------+
| mid('Quadratically',5,6) |
+--------------------------+
| ratica
|
+--------------------------+
1 row in set (0.00 sec)
31
mysql> Select mod(11,4)"modulus";
+---------+
| modulus |
+---------+
|
3|
+---------+
1 row in set (0.00 sec)
32
mysql> Select power(3,2)"raised";
+--------+
| raised |
+--------+
|
9|
+--------+
1 row in set (0.04 sec)
33
44
mysql> Select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
|
1|
+--------------+
1 row in set (0.00 sec)
45
mysql> Select avg(productcost)"average" from handbags;
+------------+
| average |
+------------+
| 11137.1429 |
+------------+
1 row in set (0.27 sec)
46
mysql> Select count(*)from handbags;
+----------+
| count(*) |
+----------+
|
7|
+----------+
1 row in set (0.00 sec)
47
mysql> select max(productid)"maximum id" from handbags;
+------------+
| maximum id |
+------------+
| 24679
|
+------------+
1 row in set (0.00 sec)
48
49
mysql> Select count(productid)from handbags group by productcost;
+------------------+
| count(productid) |
+------------------+
|
1|
|
1|
|
1|
|
1|
|
1|
|
1|
|
1|
+------------------+
7 rows in set (0.00 sec)
50
mysql> Select min(productcost)"minimum cost" from handbags;
+--------------+
| minimum cost |
+--------------+
|
1200 |
+--------------+
1 row in set (0.00 sec)