一、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并保存