x <- readClipboard()
x <- read.table(
file = ‘clipboard’, sep = ‘\t’, header = TRUE)
elements <- edit(x)
#install.packages(“dplyr”)
#library(dplyr)
install.packages(“DBI”)
install.packages(“RMySQL”)
library(DBI)
library(RMySQL)
#cvs
x <- read.csv(file = ‘G:/Download/qm.csv’)
#创建数据库连接
con <- dbConnect(MySQL(), host=“localhost”, dbname=“siasr”, user=“root”, password=“123456”, DBMSencoding=“UTF8”)
dbListTables(con) #查看database下所有表格
dbSendQuery(con,“SET NAMES gbk”)
dbWriteTable(con,“grade”,x)
dbGetQuery(con, “SELECT * from grade”)
dbGetQuery(con, “SELECT 学年学期,max(期末成绩) 期末最高成绩 FROM grade group by 学年学期”)
dbGetQuery(con, "SELECT 学年学期,min(期末成绩) 期末最低成绩 FROM grade group by 学年学期 ")
dbGetQuery(con, "SELECT 学年学期,avg(期末成绩) 期末平均绩 FROM grade group by 学年学期 ")
dbGetQuery(con, “SELECT 学年学期,期末成绩,课程名称 from grade where 期末成绩=(select max(期末成绩) from grade) or 期末成绩=(select min(期末成绩) from grade)”)
dbGetQuery(con, “SELECT 学年学期,count(课程名称) 课程数量 FROM grade group by 学年学期”)
#1.
dbGetQuery(con, "SELECT 学年学期,count(课程名称) 课程数量,课程类别 from grade where 学年学期=‘2019-2020 1’ group by 课程类别 ")
dbGetQuery(con, “SELECT 学年学期,count(课程名称) 课程数量,课程类别 from grade where 学年学期=‘2019-2020 2’ group by 课程类别”)
#2.
dbGetQuery(con, “SELECT count(课程名称) 课程数量,学分,绩点 from grade group by 绩点”)
#3.
dbGetQuery(con, “SELECT avg(总评成绩) 课程数量,课程类型 from grade group by 课程类型”)
#4.
dbGetQuery(con, “SELECT 学年学期,课程名称,最终 from grade where 学年学期=‘2019-2020 1’ order by 最终”)
dbGetQuery(con, “SELECT 学年学期,课程名称,最终 from grade where 学年学期=‘2019-2020 2’ order by 最终”)
#5.
dbGetQuery(con, "SELECT 学年学期,课程名称,最终 from grade where 最终<=70 ")
#6.
dbGetQuery(con, “select 学年学期,sum(学分) from grade group by 学年学期”)
#7.
dbGetQuery(con, “select sum(绩点) from grade”)