计算满足条件的行数
我真的认为我的问题不太具体,我只是不知道如何解释。
假设我有一张包含以下列
团队 | 的 表格游戏类型 |日期 |结果
我想创建一个视图,列出有关团队的一些统计信息
SELECT team, count(*) as FROM matches GROUP BY team ORDER BY Total DESC
现在我想添加计数列 胜负
- 联赛比赛总数
- 过去一个月的
- 平局
- 目的
- 。
是在数据库中创建一个视图,而不是任何新的表或列
I really think the question I have is not too specific, I just don't know how to explain it.
Say I have a table with following Collumns
team | gameType | date | outcome
I would like to create a view that lists some statistics about the teams
SELECT team, count(*) as FROM matches GROUP BY team ORDER BY total DESC
Now I want to add columns counting the total
- which were league games
- which have been in the past month
- wins
- losses
- ties
The purpose is to create a view in the database, not any new tables or columns.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在聚合函数中使用 case 语句来仅聚合特定事件。
You can use case statements in your aggregation functions to aggregate only for specific events.
总体思路是在聚合内部使用 CASE 表达式
The general idea is to use CASE expression inside the aggregate
比使用 CASE 更简单、更易读(至少对我来说)是使用 OR:
Somewhat simpler and more readable (to me at least) than using CASE is using OR: