gpt4 book ai didi

MySQL乘法

转载 作者:太空宇宙 更新时间:2023-11-03 12:12:25 24 4
gpt4 key购买 nike

我正在尝试在 MySQL 中进行乘法运算。我有下表称为 vehicul:

id car_type car_model  number price  car_id
1 audi <model1> 2 320 1
2 audi <model2> 4 100 1
3 bmw <model1> 3 240 2
4 bmw <model2> 6 500 2
5 bmw <model3> 1 400 2

我有这个命令:

SELECT car_type, sum(price) FROM vehicul as v, GROUP BY marca

显示以下内容:

car_type  price 
audi 420
bmw 1140

但我想要的是显示数字*价格,结果是:

car_type  price 
audi 1040
bmw 4120

基本上.. sum(number*price).. 我该怎么做?我试过这样做:

SELECT car_type, sum(price*number) FROM vehicul as v, GROUP BY marca

但我得到:

#1052 - Column 'number' in field list is ambiguous 

最佳答案

选择car_type,sum(price*number) 作为price from vehicul group by car_type..

http://sqlfiddle.com/#!2/3d881/1

你应该使用 sum(field_1*field_2) 而不是 sum()*sum()

关于MySQL乘法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23676130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com