0 sql
表:
cia ( name , region , area , population , gdp )
Run Code Online (Sandbox Code Playgroud)
我正在自学SQL,并且遇到了一些我无法弄清楚的事情.我试图从数据库中提取的数据是比利时,荷兰和卢森堡的人口总数.我尝试过以下方法:
SELECT SUM(population) FROM cia WHERE name = 'Belgium' AND 'Netherlands' AND 'Luxembourg';
Run Code Online (Sandbox Code Playgroud)
返回的值似乎不正确.我错过了什么?
使用or而不是and因为单行不能同时具有这3个设置.你的name细胞只能是或者.
对于值列表,您也可以使用 IN()
SELECT SUM(population)
FROM cia
WHERE name IN('Belgium', 'Netherlands', 'Luxembourg')
Run Code Online (Sandbox Code Playgroud)