0
我如何顯示這兩個查詢在同一行的結果。事端如17/8(殺死/死亡)。 我有兩個疑問,第一:如何結合兩個結果?
$result1 = mysql_query("SELECT PlayerTable.Player AS 'Player', COUNT(CASE WHEN PlayerTable.InitiatorGroupCat = 'AIRPLANE' THEN PlayerTable.InitiatorGroupCat END) AS Airplane
FROM
(
SELECT HitTbl.InitiatorPlayer AS 'Player', DeadTbl.InitiatorGroupCat
FROM
(
SELECT *
FROM stats
WHERE (EVENT = 'S_EVENT_PILOT_DEAD')
AND InitiatorGroupCat != ''
) AS DeadTbl
JOIN
(
SELECT *
FROM stats
WHERE EVENT = 'S_EVENT_HIT'
) AS HitTbl
ON DeadTbl.InitiatorID = HitTbl.TargetID
WHERE HitTbl.Time IN
(
SELECT MAX(TIME)
FROM stats
WHERE EVENT = 'S_EVENT_HIT'
GROUP BY TargetID
)
GROUP BY DeadTbl.InitiatorID,DeadTbl.Time
ORDER BY DeadTbl.Time ASC
) AS PlayerTable
GROUP BY PlayerTable.Player
ORDER BY Airplane DESC
");
//return the array and loop through each row
$i = 1;
while ($row2 = mysql_fetch_assoc($result1))
{
?>
<tr valign="top">
<td align=center><?php echo $i ++; ?>.</td>
<td> <?php echo $row2['Player'];?></td>
<td align=center><?php echo $row2['Airplane'];?></td>
</tr>
第二個查詢:
$result2 = mysql_query("SELECT InitiatorPlayer, COUNT(CASE WHEN InitiatorGroupCat = 'AIRPLANE' THEN InitiatorGroupCat END) AS Deaths
FROM stats
WHERE (EVENT = 'S_EVENT_DEAD' OR EVENT = 'S_EVENT_PILOT_DEAD' OR EVENT = 'S_EVENT_EJECTION')
AND InitiatorGroupCat != ''
GROUP BY InitiatorPlayer
ORDER BY Airplane DESC");
展位查詢工作,但我需要在從排在第一第二的形式顯示查詢結果: 1 |玩家| 17/8(8是從第二查詢結果) 這是cmbination(在由 「/」 分隔第一查詢新列):
<?php echo $row2['Airplane']. "/".$row2['Deaths'];?>
爲什麼不只是加入第二個查詢,無論您的主鍵是在表中? – 2014-09-23 16:40:55
使用'UNION ALL' – gr3g 2014-09-23 18:55:20