use J190802

【使用J190802表】

1、创建表tbfact表,表结构是:

id int primary key 自动增长

r1 int

r2 int

r3 int

r4 int

r5 int

r6 int

b7 int

qs varchar(7)

create table tbfact(

id int primary key auto_increment,

r1 int,

r2 int,

r3 int,

r4 int,

r5 int,

r6 int,

b7 int,

qs varchar(7)

);

2、将tb_fact.sql中的所有数据插入到tbfact表中。

INSERT INTO tbfact VALUES ('1', '1', '9', '10', '16', '22', '24', '11', '2004009');

INSERT INTO tbfact VALUES ('111', '6', '9', '18', '20', '25', '33', '6', '2004119');

INSERT INTO tbfact VALUES ('112', '7', '8', '18', '21', '27', '32', '10', '2004120');

INSERT INTO tbfact VALUES ('113', '7', '13', '16', '18', '30', '32', '10', '2004121');

INSERT INTO tbfact VALUES ('266', '1', '5', '12', '14', '21', '27', '3', '2005152');

INSERT INTO tbfact VALUES ('267', '4', '5', '7', '21', '26', '29', '1', '2005153');

INSERT INTO tbfact VALUES ('268', '1', '12', '15', '19', '21', '28', '3', '2005154');

INSERT INTO tbfact VALUES ('419', '1', '14', '20', '25', '27', '31', '15', '2006152');

INSERT INTO tbfact VALUES ('420', '1', '7', '11', '20', '30', '33', '10', '2006153');

INSERT INTO tbfact VALUES ('421', '7', '14', '18', '20', '30', '33', '13', '2006154');

INSERT INTO tbfact VALUES ('573', '11', '17', '21', '29', '30', '33', '8', '2007152');

INSERT INTO tbfact VALUES ('574', '1', '4', '19', '20', '25', '31', '15', '2007153');

INSERT INTO tbfact VALUES ('575', '2', '4', '7', '9', '14', '29', '3', '2007154');

INSERT INTO tbfact VALUES ('722', '3', '5', '9', '22', '26', '28', '9', '2008148');

INSERT INTO tbfact VALUES ('723', '10', '14', '22', '28', '29', '33', '2', '2008149');

INSERT INTO tbfact VALUES ('724', '4', '19', '22', '24', '29', '32', '2', '2008150');

INSERT INTO tbfact VALUES ('725', '6', '8', '10', '14', '17', '19', '6', '2008151');

INSERT INTO tbfact VALUES ('726', '1', '4', '6', '22', '26', '30', '8', '2008152');

INSERT INTO tbfact VALUES ('727', '1', '4', '18', '21', '24', '30', '16', '2008153');

INSERT INTO tbfact VALUES ('728', '2', '5', '7', '21', '22', '26', '8', '2008154');

INSERT INTO tbfact VALUES ('729', '4', '21', '23', '24', '30', '31', '4', '2009001');

INSERT INTO tbfact VALUES ('730', '10', '14', '17', '25', '29', '33', '14', '2009002');

INSERT INTO tbfact VALUES ('879', '6', '8', '10', '16', '25', '30', '14', '2009151');

INSERT INTO tbfact VALUES ('880', '3', '4', '19', '21', '27', '28', '5', '2009152');

INSERT INTO tbfact VALUES ('881', '6', '7', '8', '20', '21', '25', '10', '2009153');

INSERT INTO tbfact VALUES ('882', '1', '7', '12', '14', '18', '25', '16', '2009154');

INSERT INTO tbfact VALUES ('1185', '8', '10', '12', '15', '22', '27', '13', '2011150');

INSERT INTO tbfact VALUES ('1186', '7', '11', '16', '19', '31', '33', '10', '2011151');

INSERT INTO tbfact VALUES ('1187', '4', '10', '11', '12', '21', '26', '13', '2011152');

INSERT INTO tbfact VALUES ('1329', '3', '5', '8', '19', '20', '27', '9', '2012141');

INSERT INTO tbfact VALUES ('1330', '5', '18', '22', '28', '29', '31', '6', '2012142');

INSERT INTO tbfact VALUES ('1331', '7', '8', '18', '25', '30', '32', '6', '2012143');

1、查询2010年的所有数据。

select * from tbfact where  qs  like '2010%'

2、查询2005年到2007年的b7列的所有数据。

select b7 from tbfact where  qs like  '2005%' or qs like  '2006%' or qs like  '2007%'

3、统计b7列中出现的数值以及各数值出现的次数。

select b7 , count(b7) from tbfact   group by b7

4、显示表中r1到r6的和值(每行的和)以及期数。

select (r1+r2+r3+r4+r5+r6) , qs  from tbfact

5、统计表中r4列中出现过的数字及这些数字出现的次数。

select r4 , count(r4) from tbfact   group by r4

6、查询表中r1到r6的和值(每行的和)的最大值。

select  max(r1+r2+r3+r4+r5+r6) from tbfact

7、统计2012年r1到r6的和值以及和值出现的次数。

select  (r1+r2+r3+r4+r5+r6)  ,count(r1+r2+r3+r4+r5+r6) from tbfact   where  qs like  '2012%' group by (r1+r2+r3+r4+r5+r6)

8、查询出现了4个连续数字的期数的所有信息(r1到r6列已按照从小到大的顺序排列)。

select  * from tbfact   where  ((r1-r2)=-1 and  (r2-r3)=-1 and (r3-r4)=-1)  or((r2-r3)=-1 and (r3-r4)=-1  and (r4-r5)=-1) or ((r3-r4)=-1  and  (r4-r5)=-1 and (r5-r6)=-1)

9、查询2009年r1到r6列的和值的平均值。

select  avg(r1+r2+r3+r4+r5+r6) from tbfact   where  qs like  '2009%' group by (r1+r2+r3+r4+r5+r6)

10、统计b7列中数字7出现的概率。

select  (select count(b7) from  tbfact  where b7=7)/ (select count(b7) from  tbfact)

mysql某一列之前加一个球_MySQL作业:三色球,概率题,子查询【诗书画唱】相关推荐

  1. 【数据库1】mysql,DDL/DML,DQL,外键约束,多表/子查询,事务,登陆,连接池,jdbc,redis,crontab,ftp,oracle,数据交换/存储/收集

    文章目录 1.mysql安装:存储:集合(内存:临时),IO流(硬盘:持久化) 1.1 服务端:双击mysql-installer-community-5.6.22.0.msi 1.2 客户端:命令行 ...

  2. mysql子查询查询子字段_MySQL知识整理7.4—子查询

    数据科学探路者:MySQL知识整理7.3-连接查询​zhuanlan.zhihu.com 四.子查询 什么是子查询? 当一个查询是另一个查询的条件时,称之为子查询.子查询可以使用几个简单命令构造功能强 ...

  3. mysql exists依赖查询_MySQL EXISTS 和 NOT EXISTS 子查询

    MySQL EXISTS 和 NOT EXISTS 子查询语法如下: 1 SELECT ... FROM table WHERE EXISTS (subquery) 该语法可以理解为:将主查询的数据, ...

  4. mysql 更新子表_mysql 在update中实现子查询的方式

    当使用mysql条件更新时--最先让人想到的写法 UPDATE buyer SET is_seller=1 WHERE uid IN (SELECT uid FROM seller) 此语句是错误的, ...

  5. mysql把一行保存到另一个表_MYSQL:如何复制整个行从一个表到另一个在MySQL与第二个表有一个额外的列?...

    为了完善Zed的答案,并回答你的评论: INSERT INTO dues_storage SELECT d.*, CURRENT_DATE() FROM dues d WHERE id = 5; 见T ...

  6. mysql行转列函数_一个小知识点-Hive行转列实现Pivot

    前言 传统关系型数据库中,无论是Oracle(11g之后)还是SQLserver(2005之后),都自带了Pivot函数实现行转列功能,本文主要讲述在Hive中实现行转列的两种方式. 传统数据库方式 ...

  7. mysql在学号列创建主码约束_MySQL 数据完整性

    数据库实验回顾实体完整性 实体完整性即主码的属性不能为空.而主码就可保证元组是不重复的,即主码值是不能重复的. 参照完整性 参照完整性保证外码的值要么是被参照关系中的主码值,要么取空值. 用户自定义完 ...

  8. mysql实现俩个属性加减运算_mysql加减乘除

    云数据库 MySQL 云数据库(RDS for MySQL)是稳定可靠.可弹性伸缩的云数据库服务.通过云数据库能够让您几分钟内完成数据库部署.云端完全托管,让您专注于应用程序开发,无需为数据库运维烦恼 ...

  9. mysql把表里是时间加8小时_mysql经典的8小时问题-wait_timeout

    前段时间 现网突然频繁报出 连接不上数据库,偶滴的妖孽,其他地方都是用mysql,也没遇到这个问题呀. java.io.EOFExceptionat at com.mysql.jdbc.MysqlIO ...

最新文章

  1. Spring boot(五)模板引擎 Thymeleaf
  2. Java_io体系之BufferedWriter、BufferedReader简介、走进源码及示例——16
  3. 高并发高负载网站的系统架构
  4. 为什么 wait 方法要在 synchronized 中调用?
  5. Sentinel(二十)之Envoy RLS Token Server
  6. 致力微商_致力于自己。 致力于公益组织。
  7. 计算机应用杂志投稿,计算机类杂志 (可网上投稿)
  8. UVA515 King
  9. java Comparable 和 Cloneable接口
  10. python分析pcap文件_Python读取pcap文件
  11. 2020-2021学年第二学期期末考试《药物治疗学》大作业
  12. python3刷火车票_Python3实现抢火车票功能(上)
  13. 关于 NLP 中的 tokenize 总结
  14. 虚拟服务器跟目录,如何找虚拟主机根目录?
  15. 树的左视图(Java)
  16. Fluent UDF 获取组分传输模型中的摩尔分数或分压力
  17. 使用 tcpcopy 线上导流及回放
  18. 看电影学英语五招必备
  19. JHOK-ZBL1漏电继电器
  20. 北京课工场教育科技公司喜获第八届中国软件杯企业突出贡献奖

热门文章

  1. Windows与Linux系统拷贝文件之pscp的使用
  2. 使用DPM还原exchange 2013已删除邮箱数据
  3. VS环境下的makefile编译
  4. 误删/etc/passwd的修复
  5. 多线程访问全局变量和局部变量
  6. text/html与text/plain有什么区别?
  7. 从Web借鉴UI设计
  8. Android开发之旅:android架构
  9. oracle易忘函数用法(4)
  10. 计算机windows多用户,windows Server 2012 专业版配置多用户远程桌面连接