Mark20151225

SELECT
review.*
FROM
`xx_review` review,
`xx_order_item` item,
xx_order_group gp
LEFT JOIN xx_member_score score ON gp.order_form = score.`member_order`
WHERE
CHAR_LENGTH(review.`content`)>= 10
and gp.id=item.order_group
AND review.`order_items` = item.`id`
AND score.`id` IS NULL


INSERT INTO xx_member_score(member,username,score_type, score_rule , rule_description,score_value,surplus, record_time, member_order,`create_date`,`modify_date`,operator)

SELECT
form.`member` member,member.`username`,2 score_type,11 score_rule,'每成功评论一次,赠送5积分' rule_description,5 score_value,0 surplus,review.`create_date` record_time,form.`id` member_order,review.`create_date`,review.`modify_date`,NULL
FROM
`xx_review` review,
`xx_order_item` item,
xx_order_form form,
`xx_member` member,
xx_order_group gp
LEFT JOIN xx_member_score score ON gp.order_form = score.`member_order`
WHERE
CHAR_LENGTH(review.`content`)>= 10
AND gp.id=item.order_group
AND form.`id`=gp.`order_form`
AND member.id=form.`member`
AND review.`order_items` = item.`id`
AND score.`id` IS NULL;


UPDATE xx_member_point t INNER JOIN ( SELECT SUM(t.`score_value`) POINT,t.`member` FROM `xx_member_score` t GROUP BY t.`member` ) t1 ON t1.member=t.`member` SET t.`point`=t1.point

你可能感兴趣的:(数据库)