About MySQL and explore DMsql

[Introduction]
DMsql refers to a database of dreams, here are just some plain sql. Actual operating results and data to explore the principle. We dream up a database table that comes with mysql table GRADE and free to create as a test.
1, the query all data
up to the dream database
select * from "SYSDBA" "GRADE ".;
About MySQL and explore DMsql

mysql database
SELECT * FROM ceshi;
About MySQL and explore DMsql

2, replacing the header
[plus without the effect is the same as]
DaMeng database
SELECT "the CLASSID" Frozen, "STU_COUNT" Red, ", TEACHER_NAME" as Red, "COURSE,"
from "the SYSDBA" "the GRADE.";

About MySQL and explore DMsql

MySQL database
the SELECT the Test AS Frozen, NAME AS WCL, the FROM NAME WCL ceshi;
About MySQL and explore DMsql
3, in combination with the new column of mysql can only dream of digital mosaic, columns, or other characters can not be joined
up to the dream database
select (123232 + 213213) as frozen from "SYSDBA . "" GRADE ";
About MySQL and explore DMsql
MySQL database
the SELECT (1232 + 13121) AS Frozen the fROM ceshi;
About MySQL and explore DMsql
4, range queries
up to the dream database
the SELECT" CLASSID "," STU_COUNT "," TEACHER_NAME "," COURSE "
from" SYSDBA GRADE "". " the WHERE "STU_COUNT" the BETWEEN 20 and 38;
About MySQL and explore DMsql
MySQL database
the sELECT the FROM ceshi the WHERE Age the BETWEEN 30 and 80;
About MySQL and explore DMsql
5, according to the first letter of the investigation
[ps] up to the dream database according to ASCII (str) to sort, mysql when creating a general selection choice utf -8 as coded
DaMeng database
SELECT
from "the SYSDBA" "the GRADE" by Order ", TEACHER_NAME.";
About MySQL and explore DMsql
MySQL database
SELECT * FROM ceshi ORDER BY Name;
About MySQL and explore DMsql

[Ps] mysql collation so what is it, explore what
the SELECT SUBSTRING (name, 1, 1), ASCII (SUBSTRING (name, 1, 1)) the FROM ceshi the ORDER BY SUBSTRING (name, 1, 1);
About MySQL and explore DMsql
6.1, (str) try to follow gbk ASCII?
SELECT SUBSTRING (name, 1,1), ASCII (CONVERT (SUBSTRING (name, 1,1) USING gbk)) FROM ceshi ORDER BY CONVERT (SUBSTRING (name, 1,1) USING gbk);
About MySQL and explore DMsql

7, a replacement for the null character
up to the dream database
up to the dream of grammar with mysql there is no null data, it skipped.
mysql database
the SELECT the COALESCE (the Name, "Frozen") from ceshi;
About MySQL and explore DMsql
. 8, [advanced] condition returns case when
DaMeng database
SELECT , (case when "STU_COUNT" <40 the then 'fuel' else 'OK' end) as frozen from . "SYSDBA" "GRADE";
About MySQL and explore DMsql
MySQL database
[ps] I think less than 100 are all human beings are immortal greater than 100.
The SELECT
, (Age the WHEN the CASE <100 THEN "mortal" ELSE 'immortal' END) as frozen from ceshi;
About MySQL and explore DMsql

9, aggregate functions
a, the AVG ()
the AVG () function calculates the average of a set of values. It ignores the calculation process is a NULL value.
DaMeng database
SELECT AVG ( "STU_COUNT") from "the SYSDBA" "the GRADE";.
MySQL database
SELECT AVG (Age) FROM ceshi;
About MySQL and explore DMsql

Two, COUNT () function
DaMeng database mysql consistent
SELECT COUNT (*) FROM ceshi;
three, SUM () function
DaMeng database mysql consistent
SELECT SUM (Age) FROM ceshi;
four, MAX () function
select max ( " STU_COUNT ") from" SYSDBA GRADE " ." ";
five, mIN () function
SELECT min (" STU_COUNT ") from" the SYSDBA the GRADE "." ";
10, round functions
mysql database

delimiter $$$
create procedure zqtest() -- 创建函数
begin
declare i int default 0;
set i=0;
start transaction;
while i<12 do
INSERT into  ceshi(uuid) VALUES (i);
set i=i+1;
end while;
commit;
end
$$$
delimiter;
call zqtest();

About MySQL and explore DMsql

Create a complete implementation process, to run in the function.
got the answer:
About MySQL and explore DMsql

Guess you like

Origin blog.51cto.com/13479739/2480879