Database command line input

First, create a database

show databases;

ues test1; into a certain database

show table; show database

set names 'gbk'; set the database garbled

select * from goods; view the goods table

select database (); check which database is currently in the database table

 drop database ceshi; drop database

Database backup and recovery requires in-depth research

 desc table name (goods); view table header structure

 show create table students; view the creation process of creating students table


-Splicing strings -select CONCAT (122,456,789)-select
name, sex, hometown, CONCAT (name, 'is', sex, 'born in', hometown) from students;

-• Length (str) containing the number of characters Syntax: select length ('abc');
-SELECT length ('name')

-• Intercept string ◦left (str, len) returns len characters at the left end of string str
-◦right (str, len) returns len characters at the right end of string str
-◦substring (str, pos, len ) Returns the position of the string str len characters  
from the beginning-pos refers to the position starting from 1
-select substring ('abc123', 2, 3)
-select right ('abc123', 2)
-select left ('abc123', 2)


-• Remove spaces ltrim (str) returns the string str with the left space removed rtrim (str) returns the string str with the right space removed

-select ltrim ('bar'), RTRIM ('bar')
-remove left and right spaces
-select ltrim (RTRIM ('bar'))

-• Case conversion, the function is as follows lower (str) upper (str)
-SELECT LOWER ('aBcD'), upper ('aBcD')

-• Find the rounded value round (n, d), n represents the original number, d represents the decimal position, the default is 0
-SELECT ROUND (1.62)
-SELECT ROUND (2.6555, 1)

-Get Pi to get 10 decimal points of
Pi-SELECT PI ()
-SELECT ROUND (PI (), 10)

-Date time function • Current date current_date () • Current time current_time () • Current date and time now ()
-select current_date (), current_time (), now ();


- • Date Format date_format (date, format) • optional format parameter values are as follows
-% Y get in return the full year
-% y get in return abbreviated year
-% m get monthly returns in January
- % d gets the day and returns the day value-
% H gets the hexadecimal hour when getting-
% h gets the hexadecimal hour when getting it-
% i gets the minute and returns the minute-
% s Get seconds, return seconds

-- select date_format('2016-12-21','%Y %m %d');
-- select date_format('2016-12-21','%Y/%m/%d');


-Case syntax: equivalent judgment
-Description: When the value is equal to a comparison value, the corresponding result will be returned; if all comparison values ​​are not equal, the result of else is returned; if there is no else and all If the comparison values ​​are not equal, return null
-Syntax:
-case value when comparison value 1 then result 1 when comparison value 2 then result 2 ... else result end

-- select case 1 
-- when 1 then 'one'
-- when 2 then 'two' 
-- else 'zero' 
-- end as result;

-- SELECT * FROM students;

-- SELECT left(name,1),sex,
-- case sex
-- when '男' then CONCAT(left(name,1),'帅哥')
-- when '女' then CONCAT(left(name,1),'美女')
-- else '保密'
-- end as res
-- from students

 

-Create view syntax create view V_table name as select statement

-- create view v_stu_scores_courses as 
-- SELECT stu.name,stu.class,sco.score,cou.name courseName FROM students stu 
-- INNER JOIN scores sco on stu.studentNo=sco.studentNo
-- INNER JOIN courses cou on sco.courseNo=sco.courseNo

-The view is not a real table, exists in the server can hide the real table structure
-SELECT * FROM v_stu_scores_courses
 

Published 29 original articles · Like1 · Visits 593

Guess you like

Origin blog.csdn.net/wennie11/article/details/104746447