我有一张表(" user_credits"),如下所示:
我正在寻找一个查询,允许通过X值增加或减少信用总数,并根据每个用户信用额的比例,按比例添加该值。 (学分总和栏目)
有什么想法吗?
这是一个很好的解决方案吗?有更好的方法吗?
UPDATE user_credits
SET credits = (
SELECT (credits + X /(SELECT SUM(credits)
FROM (SELECT * FROM user_credits) AS MYALIAS) * credits))
答案 0 :(得分:0)
您不需要所有嵌套子查询。您可以加入获取总和的查询。
node-bigcommerce:request Starting Request, with options. { path: '/oauth2/token',
hostname: 'login.bigcommerce.com',
method: 'POST',
port: 443,
headers:
{ 'User-Agent': 'node-bigcommerce/3.0.0',
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': 394 } } +0ms
node-bigcommerce:request Sending Data: {"client_id":"123456789abcdefghikl","client_secret":"123456789abcdefghikl","redirect_uri":"https://xxxxx.xxxxx.com:8080/auth","grant_type":"authorization_code","code":"<code from query>","scope":"store_v2_customers_login store_v2_customers_read_only store_v2_default store_v2_orders_read_only store_v2_transactions_read_only","context":"stores/<our_store>"} +5ms
node-bigcommerce:request Status Returned: 302 +234ms
node-bigcommerce:request Headers Returned: {"content-type":"text/html; charset=utf-8","transfer-encoding":"chunked","connection":"close","status":"302 Found","cache-control":"no-cache, no-store","strict-transport-security":"max-age=31536000, max-age=31536000; includeSubdomains","pragma":"no-cache","x-xss-protection":"1; mode=block","x-request-id":"123456789abcdefghikl","location":"https://login.bigcommerce.com/login","p3p":"CP=\"ALL DSP COR CURa ADMa DEVa OUR IND COM NAV\"","x-content-type-options":"nosniff","date":"Fri, 02 Mar 2018 23:53:16 GMT","set-cookie":["_bc_login_session=123456789abcdefghikl; path=/; expires=Sat, 03 Mar 2018 00:08:16 -0000; secure; HttpOnly"]} +1ms
node-bigcommerce:request Request complete +2ms
node-bigcommerce:request RESOLVED BODY: <html><body>You are being <a href="https://login.bigcommerce.com/login">redirected</a>.</body></html> +0ms