dongleiqiao4906 2018-04-22 22:15
浏览 103
已采纳

由于SQL语法错误,SQL查询无法通过? phpMyAdmin的

I am typing in this query:

i13 display name, price and sum quantity for all fruit, even ones with quantity null

select inventory.fruitID
concat( "$", quantity * price ) as "value"
from fruit right join inventory
on fruit.fruitID = inventory.fruitID;

I am getting this message:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( "$", quantity * price ) as "value" from fruit right join inventory on fruit.fr' at line 3

What am I doing wrong?

  • 写回答

1条回答 默认 最新

  • dougua9328 2018-04-22 22:44
    关注

    First, if you want all fruit, then use a left join with fruit as the first table. I think the query you are trying for is:

    select f.fruitID, f.price, sum(i.quantity) as total_quantity
    from fruit f left join
         inventory i
         on f.fruitID = i.fruitID
    group by f.fruitID, f.price;
    

    Notes:

    • Table aliases make the query easier to write and to read.
    • This assumes that price is in the fruit table.
    • If you want all fruit, then fruit should be the first table in the left join.
    • You see to want to sum the inventory, so that requires an aggregation function and group by.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作