该查询为:
SELECT 100.*COUNT(DISTINCT names_of_numbers.language_name)/variables.value
AS "Percentage of Indo-European languages in which the words for 2 and 10 start with the same letter."
FROM (names_of_numbers as numbers1),names_of_numbers,languages,variables
WHERE variables.variable_name='Number of Indo-European languages' and numbers1.language_name=names_of_numbers.language_name
and names_of_numbers.language_name=languages.language_name and languages.language_family='Indo-European' and
substr(numbers1.word,1,1)=substr(names_of_numbers.word,1,1) and numbers1.value=2 and names_of_numbers.value=10;
Microsoft SQL Server告诉我在第三行的)
附近有语法错误。这是怎么回事?我该如何在标准SQL中进行查询?
1条答案
按热度按时间qco9c6ql1#
You get that error because of the parentheses here:
Remove them.
Also, you must change
SUBSTR()
toSUBSTRING()
which is SQL Server's equivalent function, although for your caseLEFT()
would also work.Also, since you are aggregating with
COUNT()
the columnvariables.value
will not be allowed by SQL Server (SQLite allows it).Instead use a subquery that returns
variables.value
.Finally, use proper joins with aliases for all the tables and
ON
clauses: