Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
homework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ligang
homework
Commits
ed124077
Commit
ed124077
authored
6 years ago
by
ligang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'大的国家'
parent
c68264f9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
11-homework-ligang/big_country.py
+61
-0
No files found.
11-homework-ligang/big_country.py
0 → 100644
View file @
ed124077
#!/usr/bin/env python3
#-*- coding:utf-8-*-
"""
这里有张 World 表
+-----------------+------------+------------+--------------+---------------+
| name | continent | area | population | gdp |+
-----------------+------------+------------+--------------+---------------+|
Afghanistan | Asia | 652230 | 25500100 | 20343000 |
| Albania | Europe | 28748 | 2831741 | 12960000 |
| Algeria | Africa | 2381741 | 37100000 | 188681000 |
| Andorra | Europe | 468 | 78115 | 3712000 |
| Angola | Africa | 1246700 | 20609294 | 100990000 |
+-----------------+------------+------------+--------------+---------------+
如果一个国家的面积超过300万平方公里,或者人口超过2500万,那么这个国家就是大国家。
编写一个SQL查询,输出表中所有大国家的名称、人口和面积。例如,根据上表,我们应该输出
+--------------+-------------+--------------+
| name | population | area |
+--------------+-------------+--------------+
| Afghanistan | 25500100 | 652230 |
| Algeria | 37100000 | 2381741 |
+--------------+-------------+--------------+
请写出SQL语句
"""
"""
1、首先创建数据库 country
create database country default character set utf8 collate utf8_general_ci;
2、创建数据表:
create table world(
id int(11) not null auto_increment.
name varchar(64) not null,
continent varchar(20) not null,
area int(11) not null,
population int null,
gdp int(11) null,
primary key(id)
)engine = InnoDB default charset =utf8;
3、插入数据
insert into world(name,continent,area,population,gdp) values('Afghanistan','Asia',652230,25500100,20343000),
('Albania','Europe',28748,2831741,12960000),(...)
"""
import
pymysql
#pymysql.install_as_MySQLdb()
mydb
=
pymysql
.
Connect
(
host
=
'127.0.0.1'
,
port
=
3306
,
user
=
'root'
,
passwd
=
'root'
,
db
=
'country'
,
charset
=
'utf8'
)
cursor
=
mydb
.
cursor
()
sql
=
" select name,population,area from world where area > 300000 or population > 25000000"
cursor
.
execute
(
sql
)
rs
=
cursor
.
fetchmany
()
print
(
rs
)
cursor
.
close
()
mydb
.
close
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment