首页 > 数据库 >sql

sql

时间:2022-11-14 11:36:37浏览次数:38  
标签:gender range user sql action where id

1、所有买家各消费行为对比

#去除重复的购买行为的数据,避免刷单行为
select act

from

(selectcount(user_id) act from user_log where action='0'

union all

selectcount(user_id) act from user_log where action='1'

union all

selectcount(distinct user_id) act from user_log where action='2'

union all

selectcount(user_id) act from user_log where action='3') as temp;

2、男女买家交易对比

#统计女的购买行为的数量

selectcount(action=2) sex

from user_logul 

where gender=0;

#统计男的购买行为的数量

selectcount(action=2) sex

from user_logul 

where gender =1;

将这两个数据传入新表second_data,以便于数据可视化的时候,提升python读取数据库数据的速度

3、男女买家各个年龄段交易对比

从这个步骤开始后,后面的数据都是在原数据表user_id中筛选出日期是双十一的新表ee_data,因为数据较大,后期读取数据的速度非常慢,我就重新筛选了双十一的数据传入新表ee_data。

insert intoee_data select * from user_log ul where month =11 and day =11;

-- 查看女的各个年龄段的数量

selectage_range age, count(gender_age) sex 

from ee_dataed2  

where  gender_age =0 

group byage_range 

order byage_range; #排序

-- 查看男的各个年龄段的数量

selectage_range age, count(gender_age) 

from ee_dataed2  

where  gender_age = 1 

group byage_range 

order byage_range;

4、商品类别交易额对比 思路 先筛选出双十一的数据,选择cat_idaction=2的数量

selected.cat_id ,count( ed.action) count_num

from ee_dataed

whereed.action =2

group byed.cat_id 

order byed.cat_id ;

并且将数据传入新表cat_data,避免读取数据时二次查询,节省时间。

5、各省份的销量对比 思路与前一个相同

selected.province  ,count( ed.action)count_num

from ee_dataed

whereed.action =2

group byed.province  

order bycount_num ;

并且将数据传入新表id_pro_test,避免读取数据时二次查询,节省时间。

6、回头客预测分数对比

-- 不要user_id作为预测特征值。选择前两千条作为数据,

selectage_range ,gender ,merchant_id ,label 

from test t 

where label isnot null 

limit 0,2000;

标签:gender,range,user,sql,action,where,id
From: https://www.cnblogs.com/ray-leon/p/16888436.html

相关文章

  • 面试常考的sql题
    问题:​​sql2000自动增长id,怎样更新重用被删除过的id​​方法:---创建临时表createtable#(idint)---插入10条记录declare@idintset@id=1while@id<=10begininsert......
  • Ubuntu下MySQL安装和配置
    1安装sudoaptinstallmysql-server2设置密码2.1打开mysqlsudomysql//使用root账户不需要密码就可进入mysql2.2设置密码//切换到mysql这个数据库mysql>use......
  • 第三章 关系数据库标准语言SQL
    3.1SQL概述(略)3.2学生-课程数据库3.3数据定义数据库>模式>表、视图和索引一个数据库管理系统的实例中可以建立多个数据库,一个数据库中可以建立多个模式,一个模......
  • 使用雪花id或uuid作为Mysql主键,被老板怼了一顿!
    前言:在mysql中设计表的时候,mysql官方推荐不要使用uuid或者不连续不重复的雪花id(long形且唯一),而是推荐连续自增的主键id,官方的推荐是auto_increment,那么为什么不建议采......
  • sql script 保障一处报错,整个script 不执行
    begintranbegintry script..........endtrybegincatchprintERROR_MESSAGE()ROLLBACKtranendcatchcommit......
  • MySQL误删恢复方法1
    MySQL不同于oracle,没有闪回查询这类概念,但网上流传几个闪回的开源工具如binglog2sql、MyFlash,可以使用binglog日志进行误操作数据的恢复。笔者以前测试过binglog2sql,发......
  • MySQL误删恢复方法2
    实际工作中总会发生数据误删除的场景,在没有备份情况下,如何快速恢复误删数据就显得非常重要。本文基于MySQL的binlog日志机制,当日志格式设置为“binlog_format=ROW”时,记录......
  • SQL numeric数据类型
    作用:存储小数,但是和编程语言的float等不同,即使数据是3.00,存储时也会存储两位小数点后的数字。float类型当你给定的数据是整数的时候,那么它就以整数给你处理。0.00而实......
  • mysql中的found_rows() 与 row_count()函数
    1.found_rows()found_rows()用于查询同一连接下,上一条执行select查询返回的行数,包括show语句返回的行数。中间可以插入执行dml语句,返回依然是上一条select语句返回的行......
  • ubuntu安装 MySql5.7.bundle.tar
    1.查询是否有残留软件rpm-qa|grepmysqlrpm-qa|grepmariadb2.上传解压并安装root@kht:/kht#tar-xvfmysql-5.7.40-1.el7.x86_64.rpm-bundle.tarmysql-communi......