V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  encro  ›  全部回复第 69 页 / 共 156 页
回复总数  3103
1 ... 65  66  67  68  69  70  71  72  73  74 ... 156  
2022-03-26 10:52:04 +08:00
回复了 xiayushengfan 创建的主题 程序员 ubuntu20.04 如何安装微信
据说先登录下文件传输助手,就能登录 web 微信了。

https://filehelper.weixin.qq.com/

https://wx.qq.com/
就是看同表更新好像是需要建立临时表。不知道 8.0 了。
@CyJaySong

不知道,前面也加了 isnull 。
INSERT INTO trade_account_total_daily_record (`date`, `account_type`, `balance`)
SELECT CURRENT_DATE , 4, IFNULL((SELECT balance FROM trade_account_total_daily_record WHERE account_type = 4 ORDER BY `date` DESC LIMIT 1),0) + 10
ON DUPLICATE KEY UPDATE `balance`=`balance`

?
LIMIT 1 不是只有一行结果吗?还需要 sum?
@CyJaySong

你删掉当天存在的值再试试,说不定没跑查询或者命中 cache 呢。

INSERT INTO trade_account_total_daily_record (`date`, `account_type`, `balance`)
SELECT DATE_FORMAT(CURRENT_TIMESTAMP, '%Y-%m-%d'), 4, IFNULL(SUM(tmp.balance),0) + 10,FROM (SELECT balance FROM trade_account_total_daily_record WHERE account_type = 4 ORDER BY `date` DESC LIMIT 1) AS tmp
ON DUPLICATE KEY UPDATE `balance`=VALUES(`balance`)


我还没琢磨透 SUM(tmp.balance) 和 WHERE account_type = 4 ORDER BY `date` DESC LIMIT 1 的用意。。。。
where account_type = 4 ORDER BY date DESC LIMIT 1

索引顺序导致用不了主键索引。。。
@CyJaySong

ORDER BY date DESC LIMIT 1 ,一条语句主键,谈什么性能?
我是想每天都只加当天的,没必要去加前一天的。
@CyJaySong

明白了,你是想不存在查前一天的,再累加。
replace into trade_account_total_daily_record set `balance`=balance+10 where date=CURRENT_DATE and account_type = 4

更新日结用我这个就可以了。
哈哈,你需要一个物化视图。
果然 pg 才是最好选择。
mysql replace into 应该比你这个更好用。
SUM(balance) + LIMIT 1 我看不出这是想干啥?

看起来希望:

replace into trade_account_total_daily_record set `balance`=balance+10 where date=CURRENT_DATE and account_type = 4 ORDER BY date DESC LIMIT 1
DATE_FORMAT(CURRENT_TIMESTAMP, '%Y-%m-%d') 直接换成 CURRENT_DATE 试试?
sorry 是我看错了。
SELECT DATE_FORMAT(CURRENT_TIMESTAMP, '%Y-%m-%d'), 1, IFNULL(SUM(balance),0) + 10
FROM trade_account_total_daily_record WHERE account_type = 1 ORDER BY date DESC LIMIT 1


这条语句写的莫名其妙。
这么简单的问题。。。。。
错误提示这么明显了。。。

PRIMARY KEY (`date`, `account_type`) 重复了。。。。。
1 ... 65  66  67  68  69  70  71  72  73  74 ... 156  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3135 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 31ms · UTC 11:18 · PVG 19:18 · LAX 04:18 · JFK 07:18
Developed with CodeLauncher
♥ Do have faith in what you're doing.