The problem is: a full 20540; table state1 indicates a full 20540; successful, and a consumption table state1 indicates a successful consumption. I want to list the total charge 20540; total successful charge 20540; total charge 20540; total charge 20540; total charge 20540; total consumption 2054
The problem is: a recharge table state = 1 indicates that the recharge is successful, and a consumption table state = 1 indicates that the consumption is successful. I want to list the total value of successful recharge is greater than the total value of successful consumption. Therefore, the user ID, total value of recharge, and total consumption value are listed. Statement: SELECT. userid, SUM (. number) AS mai, SUM (I. total) AS huaFROM account AS a, info AS iWHERE. state = 1 AND. userid = I. userid AND I. state = 1 group by. useridHAVING SUM (. number)> SUM (I. total) but the total value of recharge is incorrect... For example, the account is successfully recharged four times. Consumption is successful three times. The value of the value listed is the true value * 3 times. The consumption amount is the true value * 4 times !!!! This is not the result I want !! Correct statement !!!!!!
SELECT. userid,. mai, I. hua FROM (SELECT userid, SUM (number) AS mai FROM account WHERE state = 1 group by userid) AS a, (SELECT userid, SUM (total) AS hua FROM info WHERE state = 1 group by userid) AS I WHERE. userid = I. userid AND. mai> I. hua