您能帮我进行哪些查询,以用另一个表中的数据更新一个表。
我有2个表,例如:
tbl_med_take
| id | name | med | qty |
---------------------------------
| 1 | jayson | med2 | 3 |
| 2 | may | med2 | 4 |
| 3 | jenny. | med3 | 6 |
| 4 | joel. | med3 | 4 |
tbl_med
| id | med | stocks |
-----------------------------
| 1 | med1 | 20 |
| 2 | med2 |. 17 |
| 3 | med3 | 24 |
我想要的tbl_med输出:
tbl_med
| id | med | stocks |
-----------------------------
| 1 | med1 | 20 |
| 2 | med2 |. 10 |
| 3 | med3 | 14 |
答案 0 :(得分:0)
首先使用{p>从from google.oauth2 import id_token
from google.auth.transport import requests
GOOGLE_CLIENT_ID = '320318792814-qpggflpf15hi7skl53o4vip9q7aod39f.apps.googleusercontent.com'
def auth_google(token):
CLIENT_ID = GOOGLE_CLIENT_ID
try:
# Specify the CLIENT_ID of the app that accesses the backend:
idinfo = id_token.verify_oauth2_token(token, requests.Request(), CLIENT_ID)
print idinfo
# Or, if multiple clients access the backend server:
# idinfo = id_token.verify_oauth2_token(token, requests.Request())
# if idinfo['aud'] not in [CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3]:
# raise ValueError('Could not verify audience.')
if idinfo['iss'] not in ['accounts.google.com', 'https://accounts.google.com']:
raise ValueError('Wrong issuer.')
# If auth request is from a G Suite domain:
# if idinfo['hd'] != GSUITE_DOMAIN_NAME:
# raise ValueError('Wrong hosted domain.')
# ID token is valid. Get the user's Google Account ID from the decoded token.
auth_user_id = idinfo['sub']
print auth_user_id
return auth_user_id
except ValueError:
# Invalid token
pass
获取消耗的总量
med_tbl_take
然后您可以select med,sum(quantity) as total from tbl_med_take group by med
和left join
进行相减。
med_tbl