子节点(在/存在)到连接

时间:2015-02-03 05:08:35

标签: mysql join subquery in-subquery

SELECT *, `o_cheque_request.member_id`, `o_cheque_request.wallet_id`
FROM `o_cheque_request`, `o_member`, o_memberinfo`
WHERE `o_cheque_request.member_id` = `o_member.member_id`
AND `o_member.member_id` = `o_memberinfo.member_id`
AND withdraw_date >='2012-07-21'
AND `o_cheque_request.member_id`
IN (SELECT `member_id` FROM `o_cheque_request` GROUP BY `member_id` HAVING SUM(gross_amount ) <=10000)
GROUP BY `o_cheque_request.withdraw_date`, `o_cheque_request.member_id` ORDER BY `request_id` DESC

这需要花费大约29秒的时间如何减少...使用加入...伙计们请帮助我... o_cheque_request的表结构
request_id bigint(20)unsigned NOT NULL auto_increment,
wallet_id int(11)NOT NULL默认&#39; 0&#39;,
member_id int(10)unsigned NOT NULL默认&#39; 0&#39;,
  withdraw_date日期默认为NULL,
  amount int(10)unsigned NOT NULL默认&#39; 0&#39;,
  gross_amount float(10,2)无符号NOT NULL默认&#39; 0.00&#39;,
  admin_charge float(10,2)无符号NOT NULL默认&#39; 0.00&#39;,
  tds float(10,2)无符号NOT NULL默认&#39; 0.00&#39;,
  repurchase float(10,2)无符号NOT NULL默认&#39; 0.00&#39;,
  net_amount float(10,2)无符号NOT NULL默认&#39; 0.00&#39;,
  withdraw_type varchar(50)默认为NULL,
  bank_name varchar(50)默认为NULL,
  cheque_no varchar(50)默认为NULL,
  courier_name varchar(50)默认为NULL,
  tracking_no varchar(50)默认为NULL,
  cheque_date日期默认&#39; 0000-00-00&#39;,
  PRIMARY KEY(request_id),
  KEY member_idmember_id
)ENGINE = InnoDB DEFAULT CHARSET = latin1 AUTO_INCREMENT = 4738;

1 个答案:

答案 0 :(得分:0)

尝试这个

 SELECT * FROM (
        SELECT *, `o_cheque_request.member_id`, `o_cheque_request.wallet_id`
        FROM `o_cheque_request`
        JOIN `o_member` ON `o_cheque_request.member_id` = `o_member.member_id`
        JOIN `o_memberinfo` ON `o_member.member_id` = `o_memberinfo.member_id`
        WHERE withdraw_date >='2012-07-21'
        GROUP BY `o_cheque_request.member_id` HAVING SUM(`o_cheque_request.gross_amount` ) <=10000
    ) AS T
    GROUP BY `withdraw_date`, `member_id` ORDER BY `request_id` DESC