SELECT r.shop_name,r.uid,r.product_code,r.product_title,r.group_no,r.product_price,r.record_no ,r.buy_time,r.pay_time,r.q_opentime,r.bonus_status,r.status,g.status
FROM t_busi_member_go_record r
LEFT JOIN t_busi_shop_product_batch_additional_group g ON g.id=r.group_id
WHERE r.id=72255
这个sql 在查询结果里 在加两个字段 这两个字段是另外两个sql查出来的结果
SELECT SUM(money) FROM t_busi_member_go_record WHERE STATUS != 0 AND uid =246
SELECT SUM(discount_money) FROM t_busi_member_go_record WHERE STATUS > 0 AND uid =246
就是这两个sql求和的结果 加进上面那个sql里 作为新的列查出来 怎么写?
FROM t_busi_member_go_record r
LEFT JOIN t_busi_shop_product_batch_additional_group g ON g.id=r.group_id
WHERE r.id=72255
这个sql 在查询结果里 在加两个字段 这两个字段是另外两个sql查出来的结果
SELECT SUM(money) FROM t_busi_member_go_record WHERE STATUS != 0 AND uid =246
SELECT SUM(discount_money) FROM t_busi_member_go_record WHERE STATUS > 0 AND uid =246
就是这两个sql求和的结果 加进上面那个sql里 作为新的列查出来 怎么写?
解决方案
10
没注意, 上面是MSSQL的写法….
SELECT T1.* , T2.smoney, T3.sdiscount_money From ( SELECT "1" as tid, r.shop_name,r.uid,r.product_code,r.product_title,r.group_no,r.product_price,r.record_no ,r.buy_time,r.pay_time,r.q_opentime,r.bonus_status,r.status,g.status FROM t_busi_member_go_record r LEFT JOIN t_busi_shop_product_batch_additional_group g ON g.id=r.group_id WHERE r.id=72255 ) AS T1 inner join ( SELECT "1" as tid, SUM(discount_money) as sdiscount_money FROM t_busi_member_go_record WHERE STATUS > 0 AND uid =246 ) AS T2 on T1.tid = T2.tid inner join ( SELECT "1" as tid, SUM(discount_money) as sdiscount_money FROM t_busi_member_go_record WHERE STATUS > 0 AND uid =246 ) AS T3 on T1.tid = T3.tid
10
SELECT T1.* , T2.smoney, T3.sdiscount_money From ( SELECT "1" as tid, r.shop_name,r.uid,r.product_code,r.product_title, r.group_no,r.product_price,r.record_no ,r.buy_time,r.pay_time,r.q_opentime, r.bonus_status, r.status AS rstatus, g.status AS gstatus FROM t_busi_member_go_record r LEFT JOIN t_busi_shop_product_batch_additional_group g ON g.id=r.group_id WHERE r.id=72255 ) AS T1 inner join ( SELECT "1" as tid, SUM(discount_money) as sdiscount_money FROM t_busi_member_go_record WHERE STATUS > 0 AND uid =246 ) AS T2 on T1.tid = T2.tid inner join ( SELECT "1" as tid, SUM(discount_money) as sdiscount_money FROM t_busi_member_go_record WHERE STATUS > 0 AND uid =246 ) AS T3 on T1.tid = T3.tid
10
SELECT T1.* , T2.smoney, T3.sdiscount_money From ( SELECT "1" as tid, r.shop_name,r.uid,r.product_code,r.product_title, r.group_no,r.product_price,r.record_no ,r.buy_time,r.pay_time,r.q_opentime, r.bonus_status, r.status AS rstatus, g.status AS gstatus FROM t_busi_member_go_record r LEFT JOIN t_busi_shop_product_batch_additional_group g ON g.id=r.group_id WHERE r.id=72255 ) AS T1 inner join ( SELECT "1" as tid, SUM(discount_money) as smoney FROM t_busi_member_go_record WHERE STATUS > 0 AND uid =246 ) AS T2 on T1.tid = T2.tid inner join ( SELECT "1" as tid, SUM(discount_money) as sdiscount_money FROM t_busi_member_go_record WHERE STATUS > 0 AND uid =246 ) AS T3 on T1.tid = T3.tid