SQL点滴记录

一、SQL中条件筛选的case when 用法

 1、用于表格里字段的别名控制

 

  select  product_name as 产品名称,
          --源字段只显示 1,或者 0 看不出具体涵义,需要转换
	  case when ifactive = 0 then '被动成交'
	  when ifactive = 1 then '主动成交'
	  end as 是否主动成交
  from T_CLIENT_TRADE

2、用于条件控制求和

 

select client_uid as 客户统一编码,
           --根据是否主动成交求相应的量。此处需要group by
	  sum(case ifactive when 0 then volume else 0 end)被动成交量,
	  sum(case ifactive when 1 then volume else 0 end)主动成交量
  from T_CLIENT_TRADE
 group by client_uid

二、group by 聚合函数使用

select    client_uid as 客户统一编码,
	  tradingday as 交易日,
          --非group by 包含的字段一定要使用相应聚合函数。
	  min(client_type) as 客户类型,
	  min(product_name) as 产品名称,
	  instrument_id as 合约代码,
	  sum(trade) as 成交笔数,
	  sum(volume) as 成交量,
	  sum(case ifactive when 0 then volume else 0 end)被动成交量,
	  sum(case ifactive when 1 then volume else 0 end)主动成交量
  from T_CLIENT_TRADE
  group by client_uid,tradingday,instrument_id;

三、redhat7.1系统忘记MySQL5.7.22密码

 1、vim /etc/my.cnf 文件,在[mysqld]下添加  --skip-grant-tables 保存并且退出vi。(--skip-grant-tables表示跳过权限认证进入            MySQL数据库

 2、重启mysql 服务。systemctl restart mysql

 3、直接登录MySQL,无需密码

mysql -u root

4、修改密码

mysql>use mysql;

mysql>update mysql.user set authentication_string=password("123123") where user='root';

mysql>flush privileges;

mysql>quit;

5、删除 /etc/my.cnf中添加的 --skip-grant-tables并保存

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值