在相同的查询中选择并插入查询记录
SELECT user_id, description, SUM( Credit ) AS cre, SUM( debit ) AS deb,
CASE WHEN credit > debit
THEN SUM( credit - debit )
END AS del, price, created
FROM accounts
WHERE created
BETWEEN '2013-11-04'
AND '2013-11-11'
AND description LIKE '%Amount Earned%'
OR description = 'S'
OR description = 'B'
GROUP BY user_id
要求:我想从上周的账户表中选择记录user_id,Sum(借记)和SUM(贷项)和Del - >(贷记 - 借方)将Sum和Insert记录放在同一个账户表中。
insert into (other table )
SELECT user_id, description, SUM( Credit ) AS cre, SUM( debit ) AS deb,
CASE WHEN credit > debit
THEN SUM( credit - debit )
END AS del, price, created
FROM accounts
WHERE
( created BETWEEN '2013-11-04' AND '2013-11-11' )
AND
( description LIKE '%Amount Earned%'
OR description = 'S'
OR description = 'B' )
GROUP BY user_id, created
链接地址: http://www.djcxy.com/p/62451.html