📄 type_bit.result
字号:
select 0 + b'1';0 + b'1'1select 0 + b'0';0 + b'0'0select 0 + b'000001';0 + b'000001'1select 0 + b'000011';0 + b'000011'3select 0 + b'000101';0 + b'000101'5select 0 + b'000000';0 + b'000000'0select 0 + b'10000000';0 + b'10000000'128select 0 + b'11111111';0 + b'11111111'255select 0 + b'10000001';0 + b'10000001'129select 0 + b'1000000000000000';0 + b'1000000000000000'32768select 0 + b'1111111111111111';0 + b'1111111111111111'65535select 0 + b'1000000000000001';0 + b'1000000000000001'32769drop table if exists t1,t2;create table t1 (a bit(65));ERROR 42000: Display width out of range for column 'a' (max = 64)create table t1 (a bit(0));show create table t1;Table Create Tablet1 CREATE TABLE `t1` ( `a` bit(1) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1drop table t1;create table t1 (a bit(64));insert into t1 values (b'1111111111111111111111111111111111111111111111111111111111111111'),(b'1000000000000000000000000000000000000000000000000000000000000000'),(b'0000000000000000000000000000000000000000000000000000000000000001'),(b'1010101010101010101010101010101010101010101010101010101010101010'),(b'0101010101010101010101010101010101010101010101010101010101010101');select hex(a) from t1;hex(a)FFFFFFFFFFFFFFFF80000000000000001AAAAAAAAAAAAAAAA5555555555555555drop table t1;create table t1 (a bit);insert into t1 values (b'0'), (b'1'), (b'000'), (b'100'), (b'001');Warnings:Warning 1264 Out of range value adjusted for column 'a' at row 4select hex(a) from t1;hex(a)01011alter table t1 add unique (a);ERROR 23000: Duplicate entry '' for key 1drop table t1;create table t1 (a bit(2));insert into t1 values (b'00'), (b'01'), (b'10'), (b'100');Warnings:Warning 1264 Out of range value adjusted for column 'a' at row 4select a+0 from t1;a+00123alter table t1 add key (a);explain select a+0 from t1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 index NULL a 2 NULL 4 Using indexselect a+0 from t1;a+00123drop table t1;create table t1 (a bit(7), b bit(9), key(a, b));insert into t1 values (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177), (75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380), (111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36), (116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403), (44, 307), (68, 454), (57, 135);explain select a+0 from t1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 index NULL a 5 NULL 38 Using indexselect a+0 from t1;a+00459232428293031344449565759606168687577787987889494104106108111116118119122123127explain select b+0 from t1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 index NULL a 5 NULL 38 Using indexselect b+0 from t1;b+01772451783633639849939983438202307345379135188343152206454421331233493514114646828044667368390380368118411403explain select a+0, b+0 from t1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 index NULL a 5 NULL 38 Using indexselect a+0, b+0 from t1;a+0 b+00 1774 2455 1789 36323 3624 39828 49929 39930 8331 43834 20244 30749 34556 37957 13559 18860 34361 15268 20668 45475 4277 13378 12379 34987 35188 41194 4694 468104 280106 446108 67111 368116 390118 380119 368122 118123 411127 403explain select a+0, b+0 from t1 where a > 40 and b > 200 order by 1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range a a 2 NULL 27 Using where; Using index; Using filesortselect a+0, b+0 from t1 where a > 40 and b > 200 order by 1;a+0 b+044 30749 34556 37960 34368 20668 45479 34987 35188 41194 468104 280106 446111 368116 390118 380119 368123 411127 403explain select a+0, b+0 from t1 where a > 40 and a < 70 order by 2;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range a a 2 NULL 8 Using where; Using index; Using filesortselect a+0, b+0 from t1 where a > 40 and a < 70 order by 2;a+0 b+057 13561 15259 18868 20644 30760 34349 34556 37968 454set @@max_length_for_sort_data=0;select a+0, b+0 from t1 where a > 40 and a < 70 order by 2;a+0 b+057 13561 15259 18868 20644 30760 34349 34556 37968 454select hex(min(a)) from t1;hex(min(a))0select hex(min(b)) from t1;hex(min(b))24select hex(min(a)), hex(max(a)), hex(min(b)), hex(max(b)) from t1;hex(min(a)) hex(max(a)) hex(min(b)) hex(max(b))0 7F 24 1F3drop table t1;create table t1 (a int not null, b bit, c bit(9), key(a, b, c));insert into t1 values(4, NULL, 1), (4, 0, 3), (2, 1, 4), (1, 1, 100), (4, 0, 23), (4, 0, 54),(56, 0, 22), (4, 1, 100), (23, 0, 1), (4, 0, 34);select a+0, b+0, c+0 from t1;a+0 b+0 c+01 1 1002 1 44 NULL 14 0 34 0 234 0 344 0 544 1 10023 0 156 0 22select hex(min(b)) from t1 where a = 4;hex(min(b))0select hex(min(c)) from t1 where a = 4 and b = 0;hex(min(c))3select hex(max(b)) from t1;hex(max(b))1select a+0, b+0, c+0 from t1 where a = 4 and b = 0 limit 2;a+0 b+0 c+04 0 34 0 23select a+0, b+0, c+0 from t1 where a = 4 and b = 1;a+0 b+0 c+04 1 100select a+0, b+0, c+0 from t1 where a = 4 and b = 1 and c=100;a+0 b+0 c+04 1 100select a+0, b+0, c+0 from t1 order by b desc;a+0 b+0 c+02 1 41 1 1004 1 1004 0 34 0 234 0 5456 0 2223 0 14 0 344 NULL 1select a+0, b+0, c+0 from t1 order by c;a+0 b+0 c+04 NULL 123 0 14 0 32 1 456 0 224 0 234 0 344 0 541 1 1004 1 100drop table t1;create table t1(a bit(2), b bit(2));insert into t1 (a) values (0x01), (0x03), (0x02);update t1 set b= concat(a);select a+0, b+0 from t1;a+0 b+01 13 32 2drop table t1;create table t1 (a bit(7), key(a));insert into t1 values (44), (57);select a+0 from t1;a+04457drop table t1;create table t1 (a bit(3), b bit(12));insert into t1 values (7,(1<<12)-2), (0x01,0x01ff);select hex(a),hex(b) from t1;hex(a) hex(b)7 FFE1 1FFselect hex(concat(a)),hex(concat(b)) from t1;hex(concat(a)) hex(concat(b))07 0FFE01 01FFdrop table t1;create table t1(a int, b bit not null);alter table t1 add primary key (a);drop table t1;create table t1 (a bit(19), b bit(5));insert into t1 values (1000, 10), (3, 8), (200, 6), (2303, 2), (12345, 4), (1, 0);select a+0, b+0 from t1;a+0 b+01000 103 8200 62303 212345 41 0alter table t1 engine=heap;select a+0, b+0 from t1;a+0 b+01000 103 8200 62303 212345 41 0alter table t1 add key(a, b);select a+0, b+0 from t1;a+0 b+01000 103 8200 62303 212345 41 0alter table t1 engine=myisam;select a+0, b+0 from t1;a+0 b+01 03 8200 61000 102303 212345 4create table t2 engine=heap select * from t1;select a+0, b+0 from t2;a+0 b+01 03 8200 61000 102303 212345 4drop table t1;create table t1 select * from t2;select a+0, b+0 from t1;a+0 b+01 03 8200 61000 102303 212345 4drop table t1, t2;create table t1 (a int, b time, c tinyint, d bool, e char(10), f bit(1), g bit(1) NOT NULL default 1, h char(1) default 'a');insert into t1 set a=1;select hex(g), h from t1;hex(g) h1 adrop table t1;create table t1 (a int, b time, c tinyint, d bool, e char(10), f bit(1),g bit(1) NOT NULL default 1);insert into t1 set a=1;select hex(g) from t1;hex(g)1drop table t1;create table t1 (a int, b time, c tinyint, d bool, e char(10), f bit(1), h char(1) default 'a') engine=myisam;insert into t1 set a=1;select h from t1;hadrop table t1;create table t1 (a bit(8)) engine=heap;insert into t1 values ('1111100000');Warnings:Warning 1264 Out of range value adjusted for column 'a' at row 1select a+0 from t1;a+0255drop table t1;create table t1 (a bit(7));insert into t1 values (120), (0), (111);select a+0 from t1 union select a+0 from t1;a+01200111select a+0 from t1 union select NULL;a+01200111NULLselect NULL union select a+0 from t1;NULLNULL1200111create table t2 select a from t1 union select a from t1;select a+0 from t2;a+01200111show create table t2;Table Create Tablet2 CREATE TABLE `t2` ( `a` bit(7) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1drop table t1, t2;create table t1 (id1 int(11), b1 bit(1));create table t2 (id2 int(11), b2 bit(1));insert into t1 values (1, 1), (2, 0), (3, 1);insert into t2 values (2, 1), (3, 0), (4, 0);create algorithm=undefined view v1 as select b1+0, b2+0 from t1, t2 where id1 = id2 and b1 = 0unionselect b1+0, b2+0 from t1, t2 where id1 = id2 and b2 = 1;select * from v1;b1+0 b2+00 1drop table t1, t2;drop view v1;create table t1(a bit(4));insert into t1(a) values (1), (2), (5), (4), (3);insert into t1 select * from t1;select a+0 from t1;a+01254312543drop table t1;create table t1 (a1 int(11), b1 bit(2));create table t2 (a2 int(11), b2 bit(2));insert into t1 values (1, 1), (2, 0), (3, 1), (4, 2);insert into t2 values (2, 1), (3, 0), (4, 1), (5, 2);select a1, a2, b1+0, b2+0 from t1 join t2 on a1 = a2;a1 a2 b1+0 b2+02 2 0 13 3 1 04 4 2 1select a1, a2, b1+0, b2+0 from t1 join t2 on a1 = a2 order by a1;a1 a2 b1+0 b2+02 2 0 13 3 1 04 4 2 1select a1, a2, b1+0, b2+0 from t1 join t2 on b1 = b2;a1 a2 b1+0 b2+01 2 1 13 2 1 12 3 0 01 4 1 13 4 1 14 5 2 2select sum(a1), b1+0, b2+0 from t1 join t2 on b1 = b2 group by b1 order by 1;sum(a1) b1+0 b2+02 0 04 2 28 1 1select 1 from t1 join t2 on b1 = b2 group by b1 order by 1;1111select b1+0,sum(b1), sum(b2) from t1 join t2 on b1 = b2 group by b1 order by 1;b1+0 sum(b1) sum(b2)0 0 01 4 42 2 2drop table t1, t2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -