|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 wuxiang_123 于 2012-11-27 13:20 编辑
域聚合函数:
- SELECT * FROM [明细$A:F]
- WHERE 收入=DMAX("收入","明细$A:F","车间='"&车间&"' AND 组别='"&组别&"'")
- ORDER BY 车间,组别,收入
复制代码
子查询:
- SELECT * FROM [明细$A:F]A
- WHERE 收入=(SELECT MAX(收入) FROM [明细$A:F]B WHERE A.车间=B.车间 AND A.组别=B.组别)
- ORDER BY 车间,组别,收入
复制代码
子查询-IN谓词:
- SELECT * FROM [明细$A:F]A
- WHERE 收入 IN (SELECT MAX(收入) FROM [明细$A:F]B WHERE A.车间=B.车间 AND A.组别=B.组别)
- ORDER BY 车间,组别,收入
复制代码
子查询-TOP谓词:
- SELECT * FROM [明细$A:F]A WHERE 收入=(SELECT TOP 1 收入 FROM [明细$A:F]B WHERE A.车间=B.车间 AND A.组别=B.组别 ORDER BY B.收入 DESC)
- ORDER BY 车间,组别,收入
复制代码
子查询-NOT 运算符:
- SELECT * FROM [明细$A:F]A
- WHERE NOT 收入 <ANY (SELECT MAX(收入) FROM [明细$A:F]B WHERE A.车间=B.车间 AND A.组别=B.组别)
- ORDER BY 车间,组别,收入
复制代码
子查询-ANY谓词:
- SELECT * FROM [明细$A:F]A
- WHERE 收入 =ANY (SELECT MAX(收入) FROM [明细$A:F]B WHERE A.车间=B.车间 AND A.组别=B.组别)
- ORDER BY 车间,组别,收入
复制代码
子查询-SOME谓词(与ANY同义):
- SELECT * FROM [明细$A:F]A
- WHERE 收入 =SOME (SELECT MAX(收入) FROM [明细$A:F]B WHERE A.车间=B.车间 AND A.组别=B.组别)
- ORDER BY 车间,组别,收入
复制代码
子查询-ALL谓词:
- SELECT * FROM [明细$A:F]A
- WHERE 车间 AND 收入>=ALL (SELECT 收入 FROM [明细$A:F]B WHERE A.车间=B.车间 AND A.组别=B.组别)
- ORDER BY 车间,组别,收入
复制代码
子查询-EXISTS谓词:
- SELECT * FROM [明细$A:F]A
- WHERE EXISTS (SELECT 1 FROM [明细$A:F]B WHERE A.车间=B.车间 AND A.组别=B.组别 HAVING A.收入=MAX(B.收入))
- ORDER BY 车间,组别,收入
复制代码
子查询-NOT EXISTS:
- SELECT * FROM [明细$A:F]A
- WHERE 车间 AND NOT EXISTS (SELECT 1 FROM [明细$A:F]B WHERE A.车间=B.车间 AND A.组别=B.组别 HAVING A.收入<>MAX(B.收入))
- ORDER BY 车间,组别,收入
复制代码
多表查询:
- SELECT A.* FROM [明细$A:F]A,(SELECT 车间,组别, MAX(收入) AS 最大值 FROM [明细$A:F] GROUP BY 车间,组别)B
- WHERE A.车间=B.车间 AND A.组别=B.组别 AND A.收入=B.最大值
- ORDER BY A.车间,A.组别,A.收入
复制代码
JOIN联接-内部联接:
- SELECT A.* FROM [明细$A:F]A INNER JOIN (SELECT 车间,组别, MAX(收入) AS 最大值 FROM [明细$A:F] GROUP BY 车间,组别)B
- ON A.车间=B.车间 AND A.组别=B.组别 AND A.收入=B.最大值
- ORDER BY A.车间,A.组别,A.收入
复制代码
JOIN联接-左外部联接:
- SELECT A.* FROM [明细$A:F]A LEFT JOIN (SELECT 车间,组别, MAX(收入) AS 最大值 FROM [明细$A:F] GROUP BY 车间,组别)B
- ON A.车间=B.车间 AND A.组别=B.组别 AND A.收入=B.最大值
- WHERE B.车间 IS NOT NULL
- ORDER BY A.车间,A.组别,A.收入
复制代码
JOIN联接-右外部联接:
- SELECT B.* FROM (SELECT 车间,组别, MAX(收入) AS 最大值 FROM [明细$A:F] GROUP BY 车间,组别)A RIGHT JOIN [明细$A:F]B
- ON A.车间=B.车间 AND A.组别=B.组别 AND A.最大值=B.收入
- WHERE A.车间 IS NOT NULL
- ORDER BY B.车间,B.组别,B.收入
复制代码
联合查询-按下面语句补充其他车间和组别,不能适应车间和组别动态添加:
- SELECT * FROM (SELECT TOP 1 * FROM [明细$A:F] WHERE 车间='2E' AND 组别='A' ORDER BY 收入 DESC)
- UNION ALL ……
- SELECT * FROM (SELECT TOP 1 * FROM [明细$A:F] WHERE 车间='2W' AND 组别='A' ORDER BY 收入 DESC)
复制代码 |
评分
-
5
查看全部评分
-
|