数据库 & SQL


[Err] 1146 - Table 'alarmdemo.currentInfo' doesn't exist

find / -name my.cnf
vim /etc/my.cnf
[mysqld]
# (0:大小写敏感;1:大小写不敏感)
lower_case_table_names=1
重启后
cat /etc/my.cnf

 


MySQL8.0开户授权

drop user 'xing'@'%';
CREATE USER 'xing'@'%' IDENTIFIED BY '123456';
GRANT ALL ON *.* TO 'xing'@'%';
FLUSH PRIVILEGES;
# 客户端连不上尝试下面操作
USE mysql;
ALTER USER 'xing'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;
数据库root用户 mysql -u root -p 登录不了尝试下面方式
[root@10-9-48-229 ~]# find / -name mysql.sock
/var/lib/mysql/mysql.sock
[root@10-9-48-229 ~]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

 


SC_AccessRecord记录了所有人刷卡进出闸机的记录,现在以每个人的卡号SC_CardGuidNO进行分组,找出每个人最后的刷卡记录

方式一

select s.SC_SerierNO,s.SC_DoorNO,s.SC_CardGuidNO,s.SC_EventTypeID,s.SC_InOutStatus,s.SC_AddTime
from PongeeESD6806_CN.dbo.SC_AccessRecord s
where s.SC_AddTime=(

SELECT max(SC_AddTime) 
FROM PongeeESD6806_CN.dbo.SC_AccessRecord
where s.SC_CardGuidNO=SC_CardGuidNO

) 

 

方式二

SELECT t.SC_SerierNO,t.SC_DoorNO,t.SC_CardGuidNO,t.SC_EventTypeID,t.SC_InOutStatus,t.SC_AddTime
FROM (
      SELECT SC_CardGuidNO, MAX(SC_AddTime) as SC_AddTime
      FROM PongeeESD6806_CN.dbo.SC_AccessRecord
      GROUP BY SC_CardGuidNO
) r
INNER JOIN PongeeESD6806_CN.dbo.SC_AccessRecord t
ON t.SC_CardGuidNO = r.SC_CardGuidNO AND t.SC_AddTime = r.SC_AddTime

显然,这个东西是max和group使用的入门级困惑

 


列出各个部门中工资高于本部门的平均工资的员工数和部门号,并按部门号排序

select ta.deptid,count(*)
from employee ta,  
(select deptid,avg(salary) avgsal from employee group by deptid) tb   
where ta.deptid=tb.deptid
and ta.salary>tb.avgsal
group by ta.deptid
order by ta.deptid  

 


 

posted @ 2020-05-22 16:29  夜雨秋池  阅读(202)  评论(0编辑  收藏  举报