Python--day43()

Yesterday Content:

a variant (*************) foreign key.

Unique index

unique ( 'name'): This column is not repeated
joint unique index:
UNIQUE ( 'name', ' age '): in these two columns can not be repeated

many
Department:
ID depart_name
. 1 PR
2 xxx portion

User:
ID username depart_id (foreign key constraints)
. 1. 1 the root
2 root2 2
. 3. 1 root3

one

to see traffic demand
User:
ID username depart_id (foreign key constraint)
. 1. 1 the root
2 root2 2
. 3. 1 root3

Blog:
ID user_id URL (unique foreign key constraints +)
. 1 / the root /. 1
2 / root3 /. 3

-many

User:

ID username
the root. 1
2 root2
. 3 root3


Host:
hostname ID
. 1 c1.com
2 c2.com
. 3 c3.com


user2host:

ID HID UID (unique joint foreign key +)
. 1. 1. 1
2. 1 2
. 3. 3. 1
. 4. 3. 3




two detailed operation of the data line.


by:
INSERT INTO T1 (name, Age) values ( 'LXXX', 12 is);
INSERT INTO T1 (name, Age) values ( 'LXXX', 12 is), ( 'XXXXX', 13 is), ( 'xxxxxx', 13 is);
INSERT INTO T1 (name, age) select name, age from t2;

deletion:
Delete from T1;
Delete from T1 WHERE name = 'XXX' and Age = 12 is;!

update:
update T1 SET name = 'XXX', Age = 123 WHERE name = 'xxxx' and age = 13;

query:

wildcard:
like name 'Li'
%: match all
_: matches one character

limit access to data:
limit from the start to take the first few (index) strip, the number of pieces of data to

Page: (***********)
Page = 1,2,3,4,5 ... n-
offset = 10

limit (-Page. 1) * offset, offset;

sort:
Order by column name ASC (ascending), desc (descending)


packet:
the data are grouped by a column

group by + aggregate functions (COUNT / SUM () / AVG () / max () / min ())

HAVING

connected table:
left the Join:
left the entire show

right join:
all right of the

left join


Today contents:


A job

navcate formysql

1, the query is more than 60 points all students name and student number

ideas:
that a few tables:
associate two tables: Student Score

the SELECT * from Score score.student_id = ON left the Join Student Student. sid;



query never learned "Ping" the teacher's class of students number, name



inquiry learned "Li Ping" the students of the teacher's lesson number, name



"Ping teacher" taught courses ID


query
has at least one course with students learn the same curriculum number and name student number "1," the students have learned


1 2, 4


the SELECT COURSE_ID from the WHERE student_id Score = 1; ##, 2, 4


the SELECT student_id Score from COURSE_ID in the WHERE (COURSE_ID from the SELECT WHERE the student_id. 1 = Score)

SELECT SID, SID in sname from Student WHERE (SELECT from the student_id Score COURSE_ID in WHERE (SELECT = COURSE_ID Score. 1 from the student_id WHERE) HAVING SID! =. 1)


select student.sid, student.sname from student left join score on student.sid = score.student_id where sid!=1 and course_id in (select course_id from score where student_id=1)




tee : 重定向导入某一个文件






Two pymysql (Python operations MySQL).



PIP3 install pymysql



Note:

. A conn, the Cursor run out need to close the resource connection

b query time, fetchone, fetchmany, fetchall, default returns a tuple, need to return to dictionary words:. Cursor = conn.cursor (the Cursor = pymysql.cursors.DictCursor)

c. deletion and update when we needed after execute, add conn.commit ()









Guess you like

Origin www.cnblogs.com/wangyong123/p/11031151.html