如何创建此查询 [英] how to create this query

查看:94
本文介绍了如何创建此查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建查询,如果我需要在选择行中包括两个聚合函数,并且每个函数我需要不同的分组依据以及在我的示例中条件
需要返回的playerName,以及多少个玩家能否赢得此奖金,可以先检查桌面游戏的结果是否为result =首先,以及他玩过多少次

how to create a query if i need to include two aggregate function in select row and per each function i need different group by and where conditions in my example i need to returns the playerName, and how many the player win the this can be checked if the results in table game result= first, and how many times he played

,但不知道如何处理两个聚合函数。

but do not know how to deal with two aggregate functions .

我只想加入这两个查询的结果

simply i want to join the result of this two queries

1。

select playeName,count(*)
from  player,game
where player.playerId=game.playerId and result="first"
group by game.playerId

2。

select count(*)
from game, player
where game.playerId=player.playerId
group by game.playerId

桌面游戏的属性集为
playerId,结果
的属性为牌桌玩家是
玩家e,playerId

the set of attributes for table game are playerId , result the set of attributes for table player are playerName,playerId

任何想法?

推荐答案

使用:

  SELECT p.playername,
         SUM(CASE WHEN g.result = 'first' THEN 1 ELSE 0 END),
         COUNT(*)
    FROM PLAYER p
    JOIN GAME g ON g.playerid = p.playerid
GROUP BY p.playername

这篇关于如何创建此查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆