Эксперт
  
Профиль
Группа: Завсегдатай
Сообщений: 1191
Регистрация: 5.4.2008
Репутация: нет Всего: -2
|
| Код | $sql ="SELECT `BrandID`, `BrandName`, `AffiliateID`, `UserName`, `Password`, `MinPayout`, `BrandAPI`, `IsVisible`, `Stars`, `Priority`, `BrandURL`, `BrandImageUrl`, (SELECT COUNT(`AccountID`) FROM `brandaccounts` WHERE `brandaccounts`.`BrandID` = `brands`.`BrandID`) AS `Leads`, (SELECT COUNT(`brandaccounts`.`AccountID`) FROM `brandaccounts`, `deposits`, `brands` WHERE deposits.paymentMethod != 'Bonus' && deposits.AccountID = brandaccounts.AccountID && brandaccounts.BrandID = brands.BrandID) AS `FTD`, (SELECT COUNT(`deposits`.`AccountID`) FROM `brandaccounts`, `deposits`, `brands` WHERE `brandaccounts`.`BrandID` = `brands`.`BrandID` && brandaccounts.AccountID = deposits.AccountID && deposits.paymentMethod != 'Bonus') AS `NumOfDeposit`, (SELECT SUM(`deposits`.`AccountID`) FROM `brandaccounts`, `deposits`, `brands` WHERE `brandaccounts`.`BrandID` = `brands`.`BrandID` && brandaccounts.AccountID = deposits.AccountID && deposits.paymentMethod != 'Bonus') AS `SumOfDeposit`, (SELECT round(SUM(actualBalance),2) FROM `brandaccounts` WHERE brandaccounts.BrandID = brands.BrandID) As `Balance`, (SELECT round(SUM(requests.Outcome),2) FROM requests, brandaccounts WHERE brandaccounts.BrandID = brands.BrandID AND brandaccounts.AccountID = requests.AccountID) As `Gain` FROM `brands` WHERE `PlatformID` = :PlatformID && `PartnerID` = :PartnerID";
|
в запросе перебераются бренды(brands) у кажлого бренда имеется некое количество аккаунтов(brandaccounts) возможно ноль у каждого аккаунта имеется некое количество депозитов(deposits) возможно 0 в первом запросе надо подсчитать для каждого бренда количесто аккаунтов у которых есть хотя бы один депозит где deposits.paymentMethod != 'Bonus' вот что написал: | Код | (SELECT COUNT(`brandaccounts`.`AccountID`) FROM `brandaccounts`, `deposits`, `brands` WHERE deposits.paymentMethod != 'Bonus' && deposits.AccountID = brandaccounts.AccountID && brandaccounts.BrandID = brands.BrandID) AS `FTD`,
|
Второй запрос: общее количкство депозитов для каждого аккаунта при условии что deposits.paymentMethod != 'Bonus' я меня так | Код | (SELECT COUNT(`deposits`.`AccountID`) FROM `brandaccounts`, `deposits`, `brands` WHERE `brandaccounts`.`BrandID` = `brands`.`BrandID` && brandaccounts.AccountID = deposits.AccountID && deposits.paymentMethod != 'Bonus') AS `NumOfDeposit`
|
Третий запрос: сумма всех депозитов для каждого аккаунта при условии что deposits.paymentMethod != 'Bonus' пока так | Код | (SELECT SUM(`deposits`.`AccountID`) FROM `brandaccounts`, `deposits`, `brands` WHERE `brandaccounts`.`BrandID` = `brands`.`BrandID` && brandaccounts.AccountID = deposits.AccountID && deposits.paymentMethod != 'Bonus') AS `SumOfDeposit`
|
но все три подзпроса выдают для каждой строки какую то общию цифру для всей таблицы! Как подправить??? вот схемы таблиц: brandaccounts | Код | CREATE TABLE IF NOT EXISTS `brandaccounts` ( `AccountID` int(11) NOT NULL, `UserID` int(11) NOT NULL, `BrandID` int(11) NOT NULL, `LoginEmail` varchar(50) NOT NULL, `LoginID` int(11) NOT NULL, `LoginPassword` varchar(50) DEFAULT NULL, `initialBalance` double NOT NULL DEFAULT '0', `actualBalance` double NOT NULL DEFAULT '0', `IsAutoTrade` tinyint(1) NOT NULL DEFAULT '0', `MaxBet` int(11) NOT NULL DEFAULT '10', `MaxStopLoss` int(11) NOT NULL DEFAULT '0', `MaxTakeProfit` int(11) DEFAULT '0', `IsTestAccount` bit(1) NOT NULL, `VIPGroup` varchar(45) DEFAULT 'Regular' ) ENGINE=InnoDB
|
brands | Код | CREATE TABLE IF NOT EXISTS `brands` ( `BrandID` int(11) NOT NULL, `PartnerID` int(11) NOT NULL, `AffiliateID` int(11) NOT NULL, `UserName` varchar(50) NOT NULL, `Password` varchar(50) NOT NULL, `BrandName` varchar(50) NOT NULL, `BrandURL` longtext NOT NULL, `BrandAPI` longtext NOT NULL, `BrandJSON` longtext, `BrandAPIType` int(11) NOT NULL, `PlatformID` int(11) DEFAULT NULL, `Stars` int(11) DEFAULT '5', `Priority` int(11) DEFAULT '0', `BrandImageUrl` longtext, `AcceptUS` int(11) DEFAULT '0', `AcceptEU` int(11) DEFAULT '0', `AcceptNONEU` int(11) DEFAULT '0', `IsVisible` int(11) DEFAULT '1', `Countries` varchar(250) DEFAULT NULL ) ENGINE=InnoDB
|
deposits: | Код | CREATE TABLE IF NOT EXISTS `deposits` ( `AccountID` int(11) NOT NULL, `RemoteID` int(11) NOT NULL, `Amount` int(11) NOT NULL, `paymentMethod` varchar(50) NOT NULL, ) ENGINE=InnoDB
|
|