标签:icc span format 内连接 mft asi business conf psi
select distinct Salary as SecondHighestSalary from Employee order by Salary desc limit 1 offset 1;
select d.Name as Department,e.Name as Employee,e.Salary from Employee e inner join Department d on e.DepartmentId = d.Id and e.Salary >=( select max(Salary) from Employee where DepartmentId = d.Id );
select class from courses group by class having count(distinct student)>=5;
select Score,( select count(distinct Score) from Scores where Score >= s.score) as Rank from Scores s order by Score desc;
如何统计某张表里每个小时(存的年月日时分秒格式)的数据量
SELECT DATE_FORMAT(TimeStart, ‘%Y-%m-%d %H:00:00‘) AS time, COUNT(*) AS num FROM track WHERE Flag = 0 AND Duration >= 300 GROUP BY time ORDER BY time;
输出某个字段下值出现次数超过三次的值
SELECT business_unit_code from t_replenish_config GROUP BY business_unit_code HAVING count( *)>3;
内连接是一种一一映射关系,就是两张表都有的才能显示出来 用韦恩图表示是两个集合的交集,如图:
SELECT A.PK AS A_PK,A.Value AS A_Value,B.PK AS B_PK,B.Value AS B_Value FROM table_a A INNER JOIN table_b B ON A.PK = B.PK;
2.LEFT JOIN (左连接)
左连接是左边表的所有数据都有显示出来,右边的表数据只显示共同有的那部分,没有对应的部分只能补空显示,所谓的左边表其实就是指放在left join的左边的表
用韦恩图表示如下:
SELECT A.PK AS A_PK,A.Value AS A_Value,B.PK AS B_PK,B.Value AS B_Value FROM table_a A LEFT JOIN table_b B ON A.PK = B.PK;
3.RIGHT JOIN(右连接)
右连接正好是和左连接相反的,这里的右边也是相对right join来说的,在这个右边的表就是右表
用韦恩图表示如下:
SELECT A.PK AS A_PK,A.Value AS A_Value,B.PK AS B_PK,B.Value AS B_Value FROM table_a A RIGHT JOIN table_b B ON A.PK = B.PK;
4.OUTER JOIN(外连接、全连接)
查询出左表和右表所有数据,但是去除两表的重复数据
韦恩图表示如下:
SELECT A.PK AS A_PK,A.Value AS A_Value,B.PK AS B_PK,B.Value AS B_Value FROM table_a A LEFT JOIN table_b B ON A.PK = B.PK UNION SELECT A.PK AS A_PK,A.Value AS A_Value,B.PK AS B_PK,B.Value AS B_Value FROM table_a A RIGHT JOIN table_b B ON A.PK = B.PK;
https://blog.csdn.net/u014204541/article/details/79739980
标签:icc span format 内连接 mft asi business conf psi
原文地址:https://www.cnblogs.com/turningli/p/12483377.html