---------------------------------------------------------------------用sql语句实现计算比例-------------------------------------------------------
----------取整数
select
count(*) as 人口总数,
sum(case when sex=0 then 1 else 0 end) 男人数,
sum(case when sex=0 then 1 else 0 end)/count(*)男所占比例,
sum(case when sex=1 then 1 else 0 end) 女人数,
sum(case when sex=1 then 1 else 0 end) /count(*)女所占比例
from cj_yonghu
--------------------------------------------------
人口总数 男人数 男所占比例 女人数 女所占比例
157888 92984 0 64904 0
--------------------------------------------------
--------留两位小数点,并四舍五入
--变量之间运算,如果没有指定类型,默认取整!
select
count(*) as 人口总数,
sum(case when sex=0 then 1 else 0 end) 男人数,
cast(cast(1.0*sum(case when sex=0 then 1 else 0 end)/count(*) as decimal(18,2)) as varchar(5))||'%' 男所占比例,
sum(case when sex=1 then 1 else 0 end) 女人数,
cast(cast(1.0*sum(case when sex=1 then 1 else 0 end)/count(*) as decimal(18,2)) as varchar(5))||'%' 女所占比例
from cj_yonghu
--------------------------------------------------
人口总数 男人数 男所占比例 女人数 女所占比例
157888 92984 0.59% 64904 0.41%
--------------------------------------------------
----留两位小数并乘以100
select
count(*) as 人口总数,
sum(case when sex=0 then 1 else 0 end) 男人数,
cast(cast(100.0*sum(case when sex=0 then 1 else 0 end)/count(*) as decimal(18,2)) as varchar(5))||'%' 男所占比例,
sum(case when sex=1 then 1 else 0 end) 女人数,
cast(cast(100.0*sum(case when sex=1 then 1 else 0 end)/count(*) as decimal(18,2)) as varchar(5))||'%' 女所占比例
from cj_yonghu
--------------------------------------------------
人口总数 男人数 男所占比例 女人数 女所占比例
157888 92984 58.89% 64904 41.11%
python简单的人机对话代码 python人机交互项目介绍
1、不使用函数:这种比较简单,但也存在缺陷,代码繁琐且没有用文件保存增加名字的信息,以至于每次运行,上次添加的名字都没有了(当然也可以添加哦,下面使用函数的版本解决了这些问题)1 print("*"*30)
2 print("*\t名字管理系统")
3 print("*1.增加一个姓名")
4 print("*2.删除一个姓名")
5 print
public static void main(String[] args) {
// TODO Auto-generated method stub
// double a= 300000;
double x= 300000.0000
python多线程断网 python 多线程 坑
采集数据的准备:1.网页解析:Requests 这个是Python中的Python HTTP 神库2.threading,queue,re,time 等系统模块并没有使用采集框架,除Requests模块以外,其它完全使用标准库模块。伪代码workQueue = queue.Queue() #采集任务
threads[] 采集线程。
class Mythread: #创建工作线程
p_title =
javascript new 闭包 javascript闭包概念
JavaScript闭包1、什么是闭包 百度百科对于闭包的解释是:闭包是指可以包含自由(未绑定到特定对象)变量的代码块;这些变量不是在这个代码块内或者任何全局上下文中定义的,而是在定义代码块的环境中定义(局部变量)。以代码进行阐释:function a(){ //建立函数a
var i=0; //定义变量i
function b(){ //在函数a内套入函数b