Copy of the table and ****** ***


Copy Table ***
Create Table copy_table SELECT * from Customer;
copy of the data structure
create table copy_table select * from customer where 0> 1;
copy only structural

similarities: Description index can not be copied can not be copied (increment)

recording detailed operations:

the following syntax
[] represents an optional
{} indicates mandatory
by
insert [into] table [field name] value | values (field values ....);
INTO be omitted
[field name] Alternatively
, if a write you latter value must match the write field
value is not written back to be and the structure of the table exact match
value to insert a record
values to insert multiple records

changed
update table set field name = new value [, field n = the new value n ] [where condition]
may simultaneously edit multiple fields separated by commas Note that the last field can not comma
where optionally
have to modify the record satisfy the conditions
not all modifications to
delete
delete from table [where condition]
where Optional
record delete meet the conditions will
not have to delete all
if you need to use the truncate table to delete all the table names
delete progressive delete efficient than low
line number will remain delete delete

query
complete query
select [distinct] {* | field name | aggregate function |} from the expression table
[where conditions
group by field name
having conditions
order by field names
number of displayed limit]

Note: the order of the key must be consistent with the above syntax


simple query *** ***

1. * indicates that all columns are displayed
2. the display may be manually specify column may be a plurality
3.distinct for removing duplicate records
only records taken same
column course you can also be displayed manually specify thus come weight
4. expression support four arithmetic


execution sequence
DEF SELECT ()
from () open file
where () reads each line and determining whether the condition
group () data packets
HAVING () and then filtered HAVING after filtering packets for the packet does not occur after only a single
DISTINCT () to re-
order () for screening after data sorting
limit () limit the number of displayed
last to display data in accordance with the development of the select field of

preparing the data:
Create Table STU (ID int Primary Key AUTO_INCREMENT, name char (10), Math a float, Dictionary Dictionary English a float);
INSERT into stu values (null, "Zhao", 90,30); insert into stu values (null, " Joe", 90, 60);
INSERT into stu values (null, "Joe", 90,60); insert into stu values (null, "big Joe", 10,70);
INSERT into stu values (null, " Li Qingzhao", 100,100); insert into stu values (null, " torrent", 20, 55);
INSERT INTO stu values (null, "Survival Song", 20, 55);

The total score for all query

select name, english + math scores from stu;
select name, english + 10 English from stu;
A prefix field name data fields:
name: Zhao english: 90 math: 30
required string concatenation function
concat (string)

text columns:
SELECT
concat ( "name: ", name),
the concat (" Dictionary Dictionary English: ", Dictionary Dictionary English),
the concat (" Math: ", Math)
from STU;


Things codes **
SELECT
(Case
When Dictionary Dictionary English + Math <150 the then
the concat (name," shit ")
When Math + Dictionary Dictionary English> = 150 the then
the concat (name, "Nice")
End) reviews from stu;










Guess you like

Origin www.cnblogs.com/1832921tongjieducn/p/11128876.html