赢得对手与另一个同伴的胜利

时间:2015-10-07 20:19:35

标签: sql-server tsql

我正在努力寻找建立柜台仓库的最有效方法。

将表格缩短为所需的问题信息

匹配表

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

<br>
<script type="text/javascript">
google.load('visualization', '1.1', {packages: ['line']});
google.setOnLoadCallback(drawChart);
function drawChart() {
  var data = new google.visualization.DataTable();
  data.addColumn('number', 'Day');
  data.addColumn('number', 'Stock Index(%)');


  data.addRows([
    <?=$stockIndex?>
  ]);

  var options = {
    chart: {
      title: 'Stock Index',
    },
    width: 1100,
    height: 900
  };
  var chart = new google.charts.Line(document.getElementById('stocks'));
  chart.draw(data, options);
  }
  </script>



<script type="text/javascript">
google.load('visualization', '1.1', {packages: ['line']});
google.setOnLoadCallback(drawChart);
function drawChart() {
  var data = new google.visualization.DataTable();
  data.addColumn('number', 'Day');
  data.addColumn('number', 'Stock Index(%)');
  data.addColumn('number', '12-Day EMA');  
  data.addColumn('number', '26-Day EMA');   

  data.addRows([
    <?=$stockTwelveTwentySix?>
  ]);

  var options = {
    chart: {
      title: 'Stock Index w/12-day and 26-day EMA',
    },
      width: 1100,
    height: 900
  };
  var chart = new google.charts.Line(document.getElementById('twelvetwentysixday'));
  chart.draw(data, options);
}
</script>

 <script type="text/javascript">
google.load('visualization', '1.1', {packages: ['line']});
google.setOnLoadCallback(drawChart);
function drawChart() {
  var data = new google.visualization.DataTable();
  data.addColumn('number', 'Day');
  data.addColumn('number', 'Stock Index(%)');
  data.addColumn('number', '12-Day EMA');    

  data.addRows([
    <?=$stockTwelve?>
  ]);

  var options = {
    chart: {
      title: 'Stock Index w/12-day EMA',
    },
     width: 1100,
    height: 900
  };
  var chart = new google.charts.Line(document.getElementById('twelvetwentyday'));
  chart.draw(data, options);
}
</script>

<script type="text/javascript">
google.load('visualization', '1.1', {packages: ['line']});
google.setOnLoadCallback(drawChart);
function drawChart() {
  var data = new google.visualization.DataTable();
  data.addColumn('number', 'Day');
  data.addColumn('number', 'Stock Index(%)');
  data.addColumn('number', 'Lower BB');
  data.addColumn('number', 'Upper BB');    

  data.addRows([
    <?= $bb ?>
  ]);

  var options = {
    chart: {
      title: 'Stock Index w/Bollinger Band Comparisons',
    },
     width: 1100,
    height: 900
  };
  var chart = new google.charts.Line(document.getElementById('Bollinger'));
  chart.draw(data, options);
}

 </script>


<div id="stocks"></div>
<br>
<div id="twelvetwentyday"></div>
<br>
<div id="twelvetwentysixday"></div>
<br>
<div id="Bollinger"></div>

MatchParticipants

MatchId, version, type

字符

matchId, playerid, characterid, teamid (only team1 or team2), winner (1 or 0)

10 of these rows per match

所以我想到在角色上进行角色的交叉连接,这给了我所有角色的对手的可能性,然后我会做一个大量的子查询来查看匹配表,其中id是在对方队伍中。

任何想法基本上都是我看到仓库表的样子。

characterid, name

2 个答案:

答案 0 :(得分:0)

这就是你要找的东西吗?

SELECT
  *,
  100.0 * matches/wins AS winRate
FROM
  (SELECT
    teamid,
    playerid,
    characterid AS opponentID,
    COUNT(matchId) AS matches,
    SUM(winner) AS wins
  FROM
    MatchParticipants
  GROUP BY
    teamid,
    playerid,
    characterid) w

答案 1 :(得分:0)

我认为此查询应符合您的期望:

SELECT x.[first] AS CharacterId,
       c.name,
       x.[second] AS CharacterId,
       c1.name,
       wins/loses AS ratio
FROM         
(
SELECT  m.CharacterId [first],
        m1.CharacterId [second],
        SUM(m.winner) AS wins,
        SUM(m1.winner) AS loses
FROM    MatchParticipants m
        INNER JOIN MatchParticipants m1 ON m.MatchId = m1.MatchId AND m.TeamId <> m1.TeamId
        GROUP BY
        m.CharacterId,
        m1.CharacterId
) x
LEFT JOIN Characters c ON x.[first] = c.characterid
LEFT JOIN Characters c1 ON x.[second] = c1.characterid