create table main (num int);insert into main values

create table main (num int); 

insert into main values

(3),

(12),

(15),

(25),

(23),

(29),

(34),

(37),

(32);

int num1= 3;

int num2 = 12;

int num3 = 23;

把num值处于[20,29]之间,改为20

num值处于[30,39]之间的,改为30

思路:要把列(字段)当成变量来处理

SELECT FLOOR(num/10)*10 FROM main where num >= 20 and num <= 29;

int num = 23;

System.out.println(Math.floor(num/10.0)*10);

数据库:employee

1.创建一张员工表,表明EMPLOTYEES,有四个字段,EMPLOYEE_ID:员工表(主键)、DEPT_ID:部门号、EMPLOYEE_NAME:员工姓名、EMPLOYEE_SALARY:员工工资。

问题1、写出建表语句

CREATE TABLE EMPLOYEE(
    employee_ID int primary key,
    DEPT_ID int,
    EMPLOYEE_NAME char(40),
    EMPLOYEE_SALARY decimal(8,2)
);

问题二、检索出员工工资最高的员工的姓名和工资

--方法一
SELLECT * FROM EMPLOYEE WHERE employee_salary = (select max(employee_salary)from EMPLOYEES)
--方法二
SELECT * FROM EMPLOYEE ORDER BY employee_salary DESC limit 1;   --0,1

问题三、检索出部门中员工最多的部门号和此部门的员工数量

SELECT dept_id,count(*) cno from EMPLOYEES BY dept_id order by cno desc limit 1

浮点列与定点列:

float(M,D):M是精度,D标度,就是小数点后几位。

decimal

float/double:有精度损失

decimal:定点型,精确。用于保存对准确精度有重要要求的值,例如与金钱有关的数据

double d1 = 1234.3435;
double d2 = 1234.3400;
System.out.println(d1-d2);
if ((d1 - d2) == 0.0035) {
    Sysytem.out.println("==");
} else {
    System.out.println("!=");
}
// 0.003500000000030923
// !=

Inner join 练习:

Match的host_id与guest_id都与Team中的id关联

查出2006-6-1到2006-7-1之间举行的所有比赛,并且用以下形式列出:

国安2:0  申花2006-6-21

-- 主队 得分 客队           比赛时间

-- 国安   2   : 0            2006-6-21

-- 主队 得分 客队            比赛时间

-- 国安    2  : 0             2006-6-21

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解释代码,说明爬虫实现过程:# -- coding:utf8 -- import pymysql import requests import re import pandas as pd from bs4 import BeautifulSoup def get_movies(start): url = "https://movie.douban.com/top250?start=%d&filter=" % start lists = [] headers = { "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"} html = requests.get(url,headers=headers) soup = BeautifulSoup(html.content, "html.parser") items = soup.find("ol", class_="grid_view").find_all("li") for i in items: movie = {} movie["rank"] = i.find("em").text movie["link"] = i.find("div","pic").find("a").get("href") movie["mdirecter"]=re.findall(re.compile(r'<p class="">(.*?)</p>',re.S),str(i))[0].replace("...<br/>","").replace("\n ","") movie["name"] = i.find("span", "title").text movie["score"] = i.find("span", "rating_num").text movie["quote"] = i.find("span", "inq").text if(i.find("span", "inq")) else "" lists.append(movie) return lists if name == "main": db = pymysql.connect(host="localhost",user="root",password="123456",db="maoyan",charset="utf8",port = 3306) cursor = db.cursor() cursor.execute("DROP TABLE IF EXISTS movies") createTab = """CREATE TABLE movies( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20) NOT NULL, link VARCHAR(50) NOT NULL, score VARCHAR(4) NOT NULL, descr VARCHAR(50), directer VARCHAR(100), timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP )""" cursor.execute(createTab) #采集到的数据循环插入数据中 start = 0 while (start < 250): lists = get_movies(start) for i in lists: sql = "INSERT INTO movies(name,link,score,descr,directer) VALUES(%s,%s,%s,%s,%s)" try: cursor.execute(sql, (i["name"], i["link"] , i["score"], i["quote"],i["mdirecter"])) db.commit() print(i["name"]+"...成功插入到数据库中") except: db.rollback() start += 25 db.close() cursor = db.cursor() conn = pymysql.connect(host='localhost', user='root', password='123456', port=3306, db='maoyan', charset='utf8mb4') cursor = conn.cursor() #输出评分top10 sql = "select * from movies limit 10" db = pd.read_sql(sql, conn) df = db.sort_values(by="score", ascending=False) print(df[['name', 'score']])
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值