与巨大的 UNION 子句有关的“FROM"语法错误 [英] 'FROM' syntax error involved with huge UNION clause

查看:39
本文介绍了与巨大的 UNION 子句有关的“FROM"语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在进行的一个项目(在 MS ACCESS 中)正在计算客户为汽车公司购买的每个额外选项"的数量.为此,我创建了以下查询,将每个选项放入一列,然后在下一列中对每个选项的总数求和(针对可读性和匿名性进行了编辑).

Okay, an ongoing project (in MS ACCESS) I've had is computing the number of each extra 'option' purchased by customers for a car company. To that end, I've created the following query to put every option into one column, and then sum the totals for each option in the next column(edited for readability and anonymity).

SELECT a.options, Count(*)
FROM(
SELECT TBL.Des1 AS options FROM TBL UNION ALL
SELECT TBL.Des2 AS options FROM TBL UNION ALL
SELECT TBL.Des3 AS options FROM TBL UNION ALL
SELECT TBL.Des4 AS options FROM TBL UNION ALL
SELECT TBL.Des5 AS options FROM TBL UNION ALL
SELECT TBL.Des6 AS options FROM TBL UNION ALL
SELECT TBL.Des7 AS options FROM TBL UNION ALL
SELECT TBL.Des8 AS options FROM TBL UNION ALL
SELECT TBL.Des9 AS options FROM TBL UNION ALL
SELECT TBL.Des10 AS options FROM TBL UNION ALL
SELECT TBL.Des11 AS options FROM TBL UNION ALL
SELECT TBL.Des12 AS options FROM TBL UNION ALL
SELECT TBL.Des13 AS options FROM TBL) AS a

INTO TBL_OPTION_ALL
GROUP BY a.options;

我的问题是尝试运行时出现错误FROM 子句中的语法错误".错误提示终止后,底部的 INTO 语句会突出显示.最初,我用括号将每个 SELECT 分开,但后来我收到了来自 JOIN 子句的语法错误"的错误,并发现了一个类似的问题,通过删除括号来修复.我最初也只有 (...)a 来创建别名,但我已经把它变成了 (...) AS a 因为我不确定如果创建别名的方法在 Access 中有效.

My issue is the error "Syntax error in FROM clause" upon attempt to run. Upon termination of the error prompt, the INTO statement at the bottom is highlighted. Originally, I had seperated each SELECT with parenthesis, but then I got an error of "syntax error from JOIN clause", and found a similar post with the problem, which was fixed by removing parentheses. I also originally had just (...)a to create the alias, but I have turned it into (...) AS a for this because I am not sure if that method of creating an alias works in Access.

我有一些关于我的问题所在的理论(从最可能到最不可能排序)

I have a few theories as to where my problem resides (ordered from most likely to least)

  1. 我在应该使用 [] 时使用了 (),或者
    • 我的某些 UNION 调用缺少括号,或者
    • 我需要以完全不同的方式组织我的括号,并像我以前尝试过的那样分解 UNION.

推荐答案

语法倒退.这是

Select <your columns> 
Into <destination table> 
From <source table>

所以你应该:

SELECT a.options, Count(*)
INTO TBL_OPTION_ALL
FROM(
SELECT TBL.Des1 AS options FROM TBL UNION ALL
SELECT TBL.Des2 AS options FROM TBL UNION ALL
SELECT TBL.Des3 AS options FROM TBL UNION ALL
SELECT TBL.Des4 AS options FROM TBL UNION ALL
SELECT TBL.Des5 AS options FROM TBL UNION ALL
SELECT TBL.Des6 AS options FROM TBL UNION ALL
SELECT TBL.Des7 AS options FROM TBL UNION ALL
SELECT TBL.Des8 AS options FROM TBL UNION ALL
SELECT TBL.Des9 AS options FROM TBL UNION ALL
SELECT TBL.Des10 AS options FROM TBL UNION ALL
SELECT TBL.Des11 AS options FROM TBL UNION ALL
SELECT TBL.Des12 AS options FROM TBL UNION ALL
SELECT TBL.Des13 AS options FROM TBL) AS a
GROUP BY a.options;

这篇关于与巨大的 UNION 子句有关的“FROM"语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆