从DBA那问来的,备份现有数据库表:

create table B select * from A ;
删除,重建数据库主键
alter table book_order drop primary key;
alter table book_order add primary key(bookid,platform,stat_date);

根据小时分组数据

select date_format(inserttime,'%Y-%m-%d %H'),count(userid), count(distinct userid) from pppay_order_alipay where status=8888 and moneyType=1 and inserttime > '2013-10-16' and inserttime < '2013-10-23' group by date_format(inserttime,'%Y-%m-%d %H');

select date_format(from_unixtime(dateline),'%Y-%m-%d %H'),count(userid),count(distinct userid) from pppay_order where status=4 and moneyType=1 and from_unixtime(dateline) > '2013-10-16' and from_unixtime(dateline) < '2013-10-23' group by date_format(from_unixtime(dateline),'%Y-%m-%d %H');

date_format  函数生成这样的字符串2013-10-12 00 ~ 2013-10-12 23 数据集也根据这个进行分组

concat 字符串链接函数, format控制小数位数

select area,count(distinct userid) as uv, concat(format(count(distinct userid)/119089*100,2),'%') as uv_rate,sum(pv) as pv,  concat(format(sum(pv)/1454985*100,2),'%') as pv_rate from foreigners group by area order by uv desc; 

创建视图

create view byb_booklist_view as select distinct bid,price,date_format(stat_date,'%Y-%m') as month from byb_read_list where book_type=2;

修改字段名

alter table pay_stat_foruc change price price int;

小SQL大作用的更多相关文章

  1. CSS中zoom:1的作用 ,小标签大作用

    CSS中zoom:1的作用兼容IE6.IE7.IE8浏览器,经常会遇到一些问题,可以使用zoom:1来解决,有如下作用:触发IE浏览器的haslayout解决ie下的浮动,margin重叠等一些问题. ...

  2. java中的@Override标签,小细节大作用

    转载:http://www.cnblogs.com/octobershiner/archive/2012/03/09/2388370.html 一般用途                         ...

  3. SQL 实现地区的实现树形结构递归查询(无限级分类),level为节点层级,由小至大依次

    //SQL 实现地区的实现树形结构递归查询(无限级分类),level为节点层级,由小至大依次 2018-09-25 StringBuilder areaSQL = new StringBuilder( ...

  4. c++小学期大作业攻略(一)环境配置

    UPDATE at 2019/07/20 20:21 更新了Qt连接mysql的方法,但是是自己仿照连VS的方法摸索出来的,简单测试了一下能work但是不保证后期不会出问题.如果你在尝试过程中出现了任 ...

  5. [小细节,大BUG]记录一些小问题引起的大BUG(长期更新....)

    [小细节,大BUG] 6.问题描述:当从Plist文件加载数据,放入到tableView中展示时,有时有数据,有时又没有数据.这是为什么呢?相信很多大牛都想到了:我们一般将加载的数据,转换成模型,放入 ...

  6. SQL大数据操作统计

    SQL大数据操作统计 1:select count(*) from table的区别SELECT object_name(id) as TableName,indid,rows,rowcnt FROM ...

  7. android FakeWindow的小应用大用途

    android FakeWindow的小应用大用途 在windowmanager里面有一个FakeWindow,细致一看也就是一个透明的应用覆盖到屏幕的最前端,这样有什么优点呢?首先我们还是从应用的需 ...

  8. safari 与 chrome 的小区别大BUG

    safari 与 chrome 的小区别大BUG 时间:2016-11-01 17:33:19 作者:zhongxia 原文地址:https://github.com/zhongxia245/blog ...

  9. 搜索条件两个时间,通过php数组排序,保证select语句between时间 前小后大

    //搜索条件两个时间,通过数组排序,保证select语句between时间 前小后大 $sort_array=[$_POST['clockDate1'],$_POST['clockDate2']]; ...

随机推荐

  1. Nexus Root Toolkit教程——刷机

    Nexus Root Toolkit是Nexus系列设备专属解锁.root.刷机.修复工具.本教程以Nexus7二代刷安卓5.0 Lollipop系统为实例演示刷机过程. 标签: 安卓5.0刷机教程 ...

  2. 利用php unpack读取c struct的二进制数据,struct内存对齐引起的一些问题

    c语言代码 #include <stdio.h> struct test{ int a; unsigned char b; int c; }; int main(){ FILE *fp; ...

  3. Resty 一款极简的restful轻量级的web框架

    https://github.com/Dreampie/Resty Resty 一款极简的restful轻量级的web框架 开发文档 如果你还不是很了解restful,或者认为restful只是一种规 ...

  4. C(m,n)%P

    program1 n!%P(P为质数) 我们发现n! mod P的计算过程是以P为周期的的,举例如下: n = 10, P = 3 n! = 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 ...

  5. java.lang.NoClassDefFoundError 异常

    在项目实施过程中,当访问某一个功能时,出现异常为  java.lang.NoClassDefFoundError  com/xxx/yyy/Zzzz > ,检查发现这个类实际已经存在于应用服务器 ...

  6. python3-day4(递归)

    递归 特点 递归算法是一种直接或者间接地调用自身算法的过程.在计算机编写程序中,递归算法对解决一大类问题是十分有效的,它往往使算法的描述简洁而且易于理解. 递归算法解决问题的特点: (1) 递归就是在 ...

  7. linux下使用mutt发送带附件的邮件

    echo "hello"|mutt -s "world" -a hack.jpg -- name@address.com

  8. 自定义HttpHandler

    1.创建自定义类型 2.继承IHttpHandler接口,并实现 3.配置Web.Config文件,注册类型 4.访问 public class QuickMsgSatisticsHandler : ...

  9. 使用kindeditor 注意

    ValidateRequest="false"引用编辑器要在最上端加入上面的话

  10. Android ----------获取各种路径(更新中。。。。。。)

    ##在手机中的路径 *获取应用的路径,形式:/data/data/包名 String appDataDir = getApplicationInfo().dataDir; *获取手机数据存储路径,即/ ...