これは変更されたので、ボード、アカウント、ログの 3 つのテーブルがまだあります
ブライアン・モイルズのおかげで、彼は私にひらめきを与えてくれました
これが私のコードです
$query=$S->query("
SELECT
`TBL`.`LAcc`,
`TBL`.`AId`,
`TBL`.`Add`,
`TBL`.`Lost`,
`TBL`.`LDate`,
`TBL`.`FDate`
FROM (
SELECT
(SELECT SUM(`Add`) FROM `m_rules` GROUP BY `Group`) AS `Add`,
`S`.`Account` as `LAcc`,
`P`.`Id` as `AId`,
SUM(`S`.`Loss`*`S`.`Multiple`) AS `Lost`,
MAX(`S`.`Timestamp`) AS `LDate`,
MIN(`S`.`Timestamp`) AS `FDate`
FROM `log` AS S,`account` AS P
GROUP BY `P`.`Id`
) as `TBL`
WHERE `TBL`.`FDate` <= NOW()
AND `TBL`.`LDate` >= DATE_SUB(NOW(), INTERVAL 1 DAY)
") or die(mysql_error());
while($Log=$S->fetch($query)) {
if($Log['AId']==$Log['LAcc']) {
$Score=$Log['Add']-$Log['Lost'];
} else {
$Score='Bonus';
}
/*
echoing to see results
*/
echo $Log['AId'].' : '.$Score.'<br />';
/*
This is what the query would look like Thanks to Bryan Moyles,
$S->query("INSERT INTO `board` (`Account`,`Score`, `Date`)VALUES('".$Log['Id']."', '".$Score."', 'NOW()') ON DUPLICATE KEY UPDATE Score = '".$Score."'");
*/
}
すべての結果が表示されます: アカウント ID によるグループ化
Account Id:4, Log Account:5, Add: 97.64236, Lost:141.11371 LastDate:2012-05-04 22:07:46, FirstDate:2012-05-04 22:05:48, Score:Bonus
Account Id:5, Log Account:5, Add: 97.64236, Lost:141.11371 LastDate:2012-05-04 22:07:46, FirstDate:2012-05-04 22:05:48, Score:-43.47135
Account Id:6, Log Account:5, Add: 97.64236, Lost:141.11371 LastDate:2012-05-04 22:07:46, FirstDate:2012-05-04 22:05:48, Score:Bonus
Account Id:7, Log Account:5, Add: 97.64236, Lost:141.11371 LastDate:2012-05-04 22:07:46, FirstDate:2012-05-04 22:05:48, Score:Bonus
Account Id:8, Log Account:5, Add: 97.64236, Lost:141.11371 LastDate:2012-05-04 22:07:46, FirstDate:2012-05-04 22:05:48, Score:Bonus
GROUP BY ログ アカウント ID
Account Id:4, Log Account:4, Add: 97.64236, Lost:119.67095 LastDate:2012-05-04 22:07:46, FirstDate:2012-05-04 22:06:29, Score:-22.02859
Account Id:4, Log Account:5, Add: 97.64236, Lost:542.30295 LastDate:2012-05-04 22:06:54, FirstDate:2012-05-04 22:05:48, Score:Bonus
Account Id:4, Log Account:6, Add: 97.64236, Lost:43.59465 LastDate:2012-05-04 22:07:06, FirstDate:2012-05-04 22:07:06, Score:Bonus
私は問題が解決策がわからないだけだと思います..
解決しました!
交換しました
FROM `log` AS S,`account` AS P
と
FROM `account` AS `P` LEFT JOIN `log` AS `S` ON `P`.`Id`=`S`.`Account`
元のクエリ (ここで変更および変更する前) では、アカウントとログインをP
. Id
= S
. Account
これはうまくいかなかったので、ログとアカウントを交換しただけでうまくいきました..それが問題だったとは信じられませんが、助けてくれてありがとう.