📄 select.result
字号:
4181 4 41804select t2nr,count(*) from t3 where name='gems' group by t2nr limit 20;t2nr count(*)9 119 129 139 149 159 169 179 189 199 1109 1119 1129 1139 1149 1159 1169 1179 1189 1199 1select max(t2nr) from t3 where price=983543950;max(t2nr)41807select t1.period from t3 = t1 limit 1;period1001select t1.period from t1 as t1 limit 1;period9410select t1.period as "Nuvarande period" from t1 as t1 limit 1;Nuvarande period9410select period as ok_period from t1 limit 1;ok_period9410select period as ok_period from t1 group by ok_period limit 1;ok_period9410select 1+1 as summa from t1 group by summa limit 1;summa2select period as "Nuvarande period" from t1 group by "Nuvarande period" limit 1;Nuvarande period9410show tables;Tables_in_testt1t2t3t4show tables from test like "s%";Tables_in_test (s%)show tables from test like "t?";Tables_in_test (t?)show full columns from t2;Field Type Collation Null Key Default Extra Privileges Commentauto int(11) NULL NO PRI NULL auto_increment # fld1 int(6) unsigned zerofill NULL NO UNI 000000 # companynr tinyint(2) unsigned zerofill NULL NO 00 # fld3 char(30) latin1_swedish_ci NO MUL # fld4 char(35) latin1_swedish_ci NO # fld5 char(35) latin1_swedish_ci NO # fld6 char(4) latin1_swedish_ci NO # show full columns from t2 from test like 'f%';Field Type Collation Null Key Default Extra Privileges Commentfld1 int(6) unsigned zerofill NULL NO UNI 000000 # fld3 char(30) latin1_swedish_ci NO MUL # fld4 char(35) latin1_swedish_ci NO # fld5 char(35) latin1_swedish_ci NO # fld6 char(4) latin1_swedish_ci NO # show full columns from t2 from test like 's%';Field Type Collation Null Key Default Extra Privileges Commentshow keys from t2;Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Commentt2 0 PRIMARY 1 auto A 1199 NULL NULL BTREE t2 0 fld1 1 fld1 A 1199 NULL NULL BTREE t2 1 fld3 1 fld3 A NULL NULL NULL BTREE drop table t4, t3, t2, t1;DO 1;DO benchmark(100,1+1),1,1;do default;ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1do foobar;ERROR 42S22: Unknown column 'foobar' in 'field list'CREATE TABLE t1 (id mediumint(8) unsigned NOT NULL auto_increment,pseudo varchar(35) NOT NULL default '',PRIMARY KEY (id),UNIQUE KEY pseudo (pseudo));INSERT INTO t1 (pseudo) VALUES ('test');INSERT INTO t1 (pseudo) VALUES ('test1');SELECT 1 as rnd1 from t1 where rand() > 2;rnd1DROP TABLE t1;CREATE TABLE t1 (gvid int(10) unsigned default NULL, hmid int(10) unsigned default NULL, volid int(10) unsigned default NULL, mmid int(10) unsigned default NULL, hdid int(10) unsigned default NULL, fsid int(10) unsigned default NULL, ctid int(10) unsigned default NULL, dtid int(10) unsigned default NULL, cost int(10) unsigned default NULL, performance int(10) unsigned default NULL, serialnumber bigint(20) unsigned default NULL, monitored tinyint(3) unsigned default '1', removed tinyint(3) unsigned default '0', target tinyint(3) unsigned default '0', dt_modified timestamp NOT NULL, name varchar(255) binary default NULL, description varchar(255) default NULL, UNIQUE KEY hmid (hmid,volid)) ENGINE=MyISAM;INSERT INTO t1 VALUES (200001,2,1,1,100,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\E$',''),(200002,2,2,1,101,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\C$',''),(200003,1,3,2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,0,1,20020425060427,'c:',NULL);CREATE TABLE t2 ( hmid int(10) unsigned default NULL, volid int(10) unsigned default NULL, sampletid smallint(5) unsigned default NULL, sampletime datetime default NULL, samplevalue bigint(20) unsigned default NULL, KEY idx1 (hmid,volid,sampletid,sampletime)) ENGINE=MyISAM;INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12:00:01',35);SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'wrong-date-value' AND b.sampletime < 'wrong-date-value' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;gvid the_success the_fail the_size the_timeWarnings:Warning 1292 Incorrect datetime value: 'wrong-date-value' for column 'sampletime' at row 1Warning 1292 Incorrect datetime value: 'wrong-date-value' for column 'sampletime' at row 1SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;gvid the_success the_fail the_size the_timeDROP TABLE t1,t2;create table t1 ( A_Id bigint(20) NOT NULL default '0', A_UpdateBy char(10) NOT NULL default '', A_UpdateDate bigint(20) NOT NULL default '0', A_UpdateSerial int(11) NOT NULL default '0', other_types bigint(20) NOT NULL default '0', wss_type bigint(20) NOT NULL default '0');INSERT INTO t1 VALUES (102935998719055004,'brade',1029359987,2,102935229116544068,102935229216544093);select wss_type from t1 where wss_type ='102935229216544106';wss_typeselect wss_type from t1 where wss_type ='102935229216544105';wss_typeselect wss_type from t1 where wss_type ='102935229216544104';wss_typeselect wss_type from t1 where wss_type ='102935229216544093';wss_type102935229216544093select wss_type from t1 where wss_type =102935229216544093;wss_type102935229216544093drop table t1;select 1+2,"aaaa",3.13*2.0 into @a,@b,@c;select @a;@a3select @b;@baaaaselect @c;@c6.260create table t1 (a int not null auto_increment primary key);insert into t1 values ();insert into t1 values ();insert into t1 values ();select * from (t1 as t2 left join t1 as t3 using (a)), t1;a a1 12 13 11 22 23 21 32 33 3select * from t1, (t1 as t2 left join t1 as t3 using (a));a a1 12 13 11 22 23 21 32 33 3select * from (t1 as t2 left join t1 as t3 using (a)) straight_join t1;a a1 12 13 11 22 23 21 32 33 3select * from t1 straight_join (t1 as t2 left join t1 as t3 using (a));a a1 12 13 11 22 23 21 32 33 3select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 on t1.a>1;a a1 22 23 21 32 33 3select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;a a2 13 12 23 22 33 3select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 using ( a );a123select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) using ( a );a123select * from (t1 as t2 left join t1 as t3 using (a)) left outer join t1 on t1.a>1;a a1 21 32 22 33 23 3select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;a a1 NULL2 12 22 33 13 23 3select * from (t1 as t2 left join t1 as t3 using (a)) left join t1 using ( a );a123select * from t1 left join (t1 as t2 left join t1 as t3 using (a)) using ( a );a123select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;a123select * from t1 natural left join (t1 as t2 left join t1 as t3 using (a));a123select * from (t1 as t2 left join t1 as t3 using (a)) right join t1 on t1.a>1;a aNULL 11 22 23 21 32 33 3select * from t1 right join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;a a2 13 12 23 22 33 3select * from (t1 as t2 left join t1 as t3 using (a)) right outer join t1 using ( a );a123select * from t1 right outer join (t1 as t2 left join t1 as t3 using (a)) using ( a );a123select * from (t1 as t2 left join t1 as t3 using (a)) natural right join t1;a123select * from t1 natural right join (t1 as t2 left join t1 as t3 using (a));a123select * from t1 natural join (t1 as t2 left join t1 as t3 using (a));a123select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;a123drop table t1;CREATE TABLE t1 ( aa char(2), id int(11) NOT NULL auto_increment, t2_id int(11) NOT NULL default '0', PRIMARY KEY (id), KEY replace_id (t2_id)) ENGINE=MyISAM;INSERT INTO t1 VALUES ("1",8264,2506),("2",8299,2517),("3",8301,2518),("4",8302,2519),("5",8303,2520),("6",8304,2521),("7",8305,2522);CREATE TABLE t2 ( id int(11) NOT NULL auto_increment, PRIMARY KEY (id)) ENGINE=MyISAM;INSERT INTO t2 VALUES (2517), (2518), (2519), (2520), (2521), (2522);select * from t1, t2 WHERE t1.t2_id = t2.id and t1.t2_id > 0 order by t1.id LIMIT 0, 5;aa id t2_id id2 8299 2517 25173 8301 2518 25184 8302 2519 25195 8303 2520 25206 8304 2521 2521drop table t1,t2;create table t1 (id1 int NOT NULL);create table t2 (id2 int NOT NULL);create table t3 (id3 int NOT NULL);create table t4 (id4 int NOT NULL, id44 int NOT NULL, KEY (id4));insert into t1 values (1);insert into t1 values (2);insert into t2 values (1);insert into t4 values (1,1);explain select * from t1 left join t2 on id1 = id2 left join t3 on id1 = id3left join t4 on id3 = id4 where id2 = 1 or id4 = 1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t3 system NULL NULL NULL NULL 0 const row not found1 SIMPLE t1 ALL NULL NULL NULL NULL 2 1 SIMPLE t2 ALL NULL NULL NULL NULL 1 1 SIMPLE t4 ALL id4 NULL NULL NULL 1 Using whereselect * from t1 left join t2 on id1 = id2 left join t3 on id1 = id3left join t4 on id3 = id4 where id2 = 1 or id4 = 1;id1 id2 id3 id4 id441 1 NULL NULL NULLdrop table t1,t2,t3,t4;create table t1(s varchar(10) not null);create table t2(s varchar(10) not null primary key);create table t3(s varchar(10) not null primary key);insert into t1 values ('one\t'), ('two\t');insert into t2 values ('one\r'), ('two\t');insert into t3 values ('one '), ('two\t');select * from t1 where s = 'one';sselect * from t2 where s = 'one';sselect * from t3 where s = 'one';sone select * from t1,t2 where t1.s = t2.s;s stwo two select * from t2,t3 where t2.s = t3.s;s stwo two drop table t1, t2, t3;create table t1 (a integer, b integer, index(a), index(b));create table t2 (c integer, d integer, index(c), index(d));insert into t1 values (1,2), (2,2), (3,2), (4,2);insert into t2 values (1,3), (2,3), (3,4), (4,4);explain select * from t1 left join t2 on a=c where d in (4);id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t2 ref c,d d 5 const 2 Using where1 SIMPLE t1 ALL a NULL NULL NULL 3 Using whereselect * from t1 left join t2 on a=c where d in (4);a b c d3 2 3 44 2 4 4explain select * from t1 left join t2 on a=c where d = 4;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t2 ref c,d d 5 const 2 Using where1 SIMPLE t1 ALL a NULL NULL NULL 3 Using whereselect * from t1 left join t2 on a=c where d = 4;a b c d3 2 3 44 2 4 4drop table t1, t2;CREATE TABLE t1 (i int(11) NOT NULL default '0',c char(10) NOT NULL default '',PRIMARY KEY (i),UNIQUE KEY c (c)) ENGINE=MyISAM;INSERT INTO t1 VALUES (1,'a');INSERT INTO t1 VALUES (2,'b');INSERT INTO t1 VALUES (3,'c');EXPLAIN SELECT i FROM t1 WHERE i=1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using indexDROP TABLE t1;CREATE TABLE t1 ( a BLOB, INDEX (a(20)) );CREATE TABLE t2 ( a BLOB, INDEX (a(20)) );INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five');INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five');EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USE INDEX (a) ON t1.a=t2.a;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 ALL NULL NULL NULL NULL 5 1 SIMPLE t2 ref a a 23 test.t1.a 2 EXPLAIN SELECT * FROM t1 LEFT JOIN t2 FORCE INDEX (a) ON t1.a=t2.a;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 ALL NULL NULL NULL NULL 5 1 SIMPLE t2 ref a a 23 test.t1.a 2 DROP TABLE t1, t2;CREATE TABLE t1 ( city char(30) );INSERT INTO t1 VALUES ('London');INSERT INTO t1 VALUES ('Paris');SELECT * FROM t1 WHERE city='London';cityLondonSELECT * FROM t1 WHERE city='london';cityLondonEXPLAIN SELECT * FROM t1 WHERE city='London' AND city='london';id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using whereSELECT * FROM t1 WHERE city='London' AND city='london';cityLondonEXPLAIN SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London';id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using whereSELECT * FROM t1 WHERE city LIKE '%london%' AND city='London';cityLondonDROP TABLE t1;create table t1 (a int(11) unsigned, b int(11) unsigned);insert into t1 values (1,0), (1,1), (1,2);select a-b from t1 order by 1;a-b0118446744073709551615select a-b , (a-b < 0) from t1 order by 1;a-b (a-b < 0)0 01 018446744073709551615 0select a-b as d, (a-b >= 0), b from t1 group by b having d >= 0;d (a-b >= 0) b1 1 00 1 118446744073709551615 1 2select cast((a - b) as unsigned) from t1 order by 1;cast((a - b) as unsigned)0118446744073709551615drop table t1;create table t1 (a int(11));select all all * from t1;aselect distinct distinct * from t1;aselect all distinct * from t1;ERROR HY000: Incorrect usage of ALL and DISTINCTselect distinct all * from t1;ERROR HY000: Incorrect usage of ALL and DISTINCTdrop table t1;CREATE TABLE t1 (kunde_intern_id int(10) unsigned NOT NULL default '0',kunde_id int(10) unsigned NOT NULL default '0',FK_firma_id int(10) unsigned NOT NULL default '0',aktuell enum('Ja','Nein') NOT NULL default 'Ja',vorname varchar(128) NOT NULL default '',nachname varchar(128) NOT NULL default '',geloescht enum('Ja','Nein') NOT NULL default 'Nein',firma varchar(128) NOT NULL default '');INSERT INTO t1 VALUES (3964,3051,1,'Ja','Vorname1','1Nachname','Nein','Print Schau XXXX'),(3965,3051111,1,'Ja','Vorname1111','1111Nachname','Nein','Print Schau XXXX');SELECT kunde_id ,FK_firma_id ,aktuell, vorname, nachname, geloescht FROM t1WHERE((( '' != '' AND firma LIKE CONCAT('%', '', '%'))OR(vorname LIKE CONCAT('%', 'Vorname1', '%') AND nachname LIKE CONCAT('%', '1Nachname', '%') AND 'Vorname1' != '' AND 'xxxx' != ''))AND(aktuell = 'Ja' AND geloescht = 'Nein' AND FK_firma_id = 2));kunde_id FK_firma_id aktuell vorname nachname geloeschtSELECT kunde_id ,FK_firma_id ,aktuell, vorname, nachname,geloescht FROM t1WHERE((aktuell = 'Ja' AND geloescht = 'Nein' AND FK_firma_id = 2)AND(( '' != '' AND firma LIKE CONCAT('%', '', '%') )OR( vorname LIKE CONCAT('%', 'Vorname1', '%') ANDnachname LIKE CONCAT('%', '1Nachname', '%') AND 'Vorname1' != '' AND'xxxx' != '')));kunde_id FK_firma_id aktuell vorname nachname geloeschtSELECT COUNT(*) FROM t1 WHERE ( 0 OR (vorname LIKE '%Vorname1%' AND nachname LIKE '%1Nachname%' AND 1)) AND
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -