mysql>CREATETABLE tb1 (empid VARCHAR(10), nameVARCHAR(10), age INT);mysql>INSERT INTO tb1 VALUES('A101', 'ABC', 40);mysql>INSERT INTO tb1 VALUES('A102', 'DEF', 28);mysql>INSERT INTO tb1 VALUES('A103', 'GHI', 20);mysql>INSERT INTO tb1 VALUES('A104', 'JKL', 23);mysql>INSERT INTO tb1 VALUES('A105', 'MNO', 35);
String concatenation:
SELECTCONCAT(empid, 'Mr.', name) FROM tb1;
Slice from the right:
SELECTRIGHT(empid, 2) FROM tb1;
Slice from the left:
SELECTLEFT(empid, 2) FROM tb1;
Slice starting from the 2nd character of empid and get a substring of length 3:
SELECTSUBSTRING(empid, 2, 3) FROM tb1;
Repeat for a variable times (used for drawing graphs):
SELECTREPEAT('.', age) FROM tb1;
Print a string reversely:
SELECTREVERSE(name) FROM tb1;
Date and Time
Get current time with NOW():
mysql>CREATETABLE t_now (a INT AUTO_INCREMENT PRIMARY KEY, b DATETIME);mysql>INSERT INTO t_now (b) VALUES(NOW());mysql>INSERT INTO t_now (b) VALUES(NOW());mysql>INSERT INTO t_now (b) VALUES(NOW());mysql>INSERT INTO t_now (b) VALUES(NOW());mysql>INSERT INTO t_now (b) VALUES(NOW());