我不明白我的 SQL 中的语法错误

问题描述 投票:0回答:1

#1064 - 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'FROM Totaldata, eventvenue, band 附近使用的正确语法 WHERE Totaldata.band_name = eventvenue.headlin' 在第 3 行

INSERT INTO eventbandrevenue
SELECT DISTINCT eventvenue.eventvenue_id,
totaldata.band_name, 
(0.60*(SELECT DISTINCT eventvenue.ticket_revenue 
    FROM eventvenue, band 
    WHERE eventvenue.headliner = band.band_name), 
(0.60*(SELECT DISTINCT eventvenue.merchanndise_sales
    FROM eventvenue, band 
    WHERE eventvenue.headliner = band.band_name)),
((0.60* (SELECT DISTINCT eventvenue.ticket_revenue 
  FROM eventvenue, band 
  WHERE eventvenue.headliner = band.band_name) 
  + 
  0.60*(SELECT DISTINCT eventvenue.merchanndise_sales 
  FROM eventvenue, band 
  WHERE eventvenue.headliner = band.band_name)))
FROM totaldata, eventvenue, band
WHERE totaldata.band_name = eventvenue.headliner
sql phpmyadmin
1个回答
0
投票
  • 每次计算前都有多余的左括号,导致语法错误。
  • merchanndise_sales
    可能是一个错字,可能应该是
    merchandise_sales
  • 子查询不引用外部查询的表。
  • 主查询中的连接需要条件

下面删除了不必要的子查询并使用显式连接。

    INSERT INTO eventbandrevenue
    SELECT DISTINCT 
        ev.eventvenue_id,
        td.band_name,
        (0.60 * ev.ticket_revenue) as ticket_revenue_share,
        (0.60 * ev.merchandise_sales) as merchandise_revenue_share,
        (0.60 * (ev.ticket_revenue + ev.merchandise_sales)) as total_revenue_share
    FROM totaldata td
    JOIN eventvenue ev ON td.band_name = ev.headliner
    JOIN band b ON ev.headliner = b.band_name
© www.soinside.com 2019 - 2024. All rights reserved.