我有以下表格:MySQL的聚合函數內加入
CREATE TABLE `funds_balance` (
`idBUSINESS` int(11) NOT NULL,
`PREMIUM_POSITIONS_CREDIT` decimal(18,2) NOT NULL DEFAULT '0.00',
PRIMARY KEY (`idBUSINESS`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `elevated_business_queue` (
`idBUSINESS` int(11) NOT NULL,
`KEYWORD_TEXT` varchar(200) NOT NULL,
`CITY` varchar(50) NOT NULL,
`BID_AMOUNT` decimal(18,2) NOT NULL,
`NO_OF_DAYS` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
我想選擇從有足夠的資金來支付他們從funds_balance表中的所有出價elevated_business_queue表業務。我想出了以下查詢:
SELECT ebq.idBUSINESS
, KEYWORD_TEXT
, CITY
, BID_AMOUNT
FROM elevated_business_queue ebq
JOIN funds_balance fb
ON fb.idBUSINESS = ebq.idBUSINESS
GROUP
BY idBUSINESS
HAVING PREMIUM_POSITIONS_CREDIT >= (SUM(ebq.BID_AMOUNT) + (ROUND((12.36/100)*SUM(ebq.BID_AMOUNT)), 2));
但它不起作用。我收到錯誤未知列PREMIUM_POSITIONS_CREDIT。爲什麼?
Premium_positions_credit不是在結果集中 – Strawberry