· 6 years ago · Nov 20, 2019, 12:40 PM
1select version() as 'mysql version';
2
3
4
5drop table if exists components;
6create table components (
7 id SERIAL PRIMARY KEY,
8 name VARCHAR(20),
9 users VARCHAR(20),
10 birthday DATE
11 );
12insert into components (name) VALUES ('Processor'), ('Motherboard'),
13 ('Vidocard'),('Harddrive'),('memory');
14
15insert into components (users,birthday) VALUES
16('Aleksandr', '2019-12-12'),
17('Sergey','2014-01-12'),
18('Sasha','2014-11-13'),
19 ('Yura','2011-03-22'),
20 ('Maria','2012-04-15');
21
22select *
23from components
24#where id >2 and id <4; Выборка из интервала
25#where id between 3 and 4; Выборка из интервала
26#where id NOT between 3 and 4; Выборка выборка не входящая в интервал
27
28#where id IN (1,2,4); входят в список при null dвсегда будет null
29#where id NOT IN (1,2,4); все что не входит в список
30
31# % - любое кол-во символов или их отсутвие
32# _ - ровно один символ
33#where name like '%rd'; текст заканчивающийся на 'rd'
34#where name like '______'; текст из любых 6 знаков
35#where name like '15\%' - тут применяется экранировние обратным слешом
36
37#where birthday > '2011-11-11' and birthday < '2015-11-11'; числа
38#преобразуются встроки все ровно. Выборка дат
39#where birthday like '2014%'; тот же метод но проще через LIKE
40# RLIKE = регулярные выражения
41
42
43
44
45#drop table if exists components;
46#create table components (
47 # x INT,
48 # y INT,
49 # summ INT AS (x +y)
50#);
51
52#insert into components (x, y) VALUES (1,4), (3,23), (12,3);
53
54#select *
55#from components;