本文介绍了MySql选择里面另一个选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么办法吗?
SELECT sum(price) from table2 WHERE id=(SELECT theid FROM table1 WHERE user_id="myid")
我有一个表1,其中包含用户购买的商品ID.我想计算用户购买的所有物品的总和.
I have table1 with items' IDs, that a user has purchased. I want to calculate the sum of all items purchased by user.
以上查询合法吗?如果没有,正确的格式是什么?
Is the query above legal? If not, what's the correct form?
推荐答案
将where id=(SELECT
更改为where id IN (SELECT
或者您真正想要的可能是:
Or what you really want is probably:
SELECT sum(price) FROM table2 INNER JOIN table1 ON table2.id = table1.theid WHERE table1.user_id = 'my_id'
这篇关于MySql选择里面另一个选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!