我正在尝试创建一个返回结果的查询,不包括列中的4个特定值。
这是我的代码:
SELECT CustomerID,
ContactName,
Country
FROM Customers
WHERE CustomerID IN (SELECT CustomerID
FROM Customers
WHERE (Country <> ('UK')('Australia')('Canada')));
如果我只排除一个国家而不是多个国家,则此方法有效。
提前感谢您提供的任何帮助。
答案 0 :(得分:2)
使用ValueError: attempted relative import beyond top-level package
运算符
列表应该用逗号分隔,不需要为列表中的每个值打开/关闭括号。此外,您不需要NOT IN
只需添加过滤器sub-query
子句
Where
确保您未在列表中传递任何SELECT CustomerID,
ContactName,
Country
FROM Customers
WHERE Country NOT IN ( 'USA', 'UK', 'Australia', 'Canada' )
值,因为NULL
在列表中存在NOT IN
值时失败
答案 1 :(得分:1)
import pygame
import random
import sys
pygame.mixer.pre_init(44100, -16, 2, 2048)
pygame.init()
pygame.mixer.music.load('grand-metropolis.mp3')
pygame.mixer.music.play()
pygame.mixer.music.set_volume(0.7)
SCR_WID, SCR_HEI = 640, 480
screen = pygame.display.set_mode((SCR_WID,SCR_HEI), 0, 16)
pygame.display.set_caption("Ever Emerald")
font = pygame.font.SysFont("white", 32)
bg = pygame.image.load("sddefault.jpg")
class Player():
def __init__(self, SCR_WID, SCR_HEI,):
self.x, self.y = SCR_WID, SCR_HEI/2
self.speed = 3
self.padWid, self.padHei = 8, 64
self.score = 0
self.scoreFont = pygame.font.Font("imagine_font.ttf", 64)
def scoring(self, screen, cord, winner):
scoreBlit = self.scoreFont.render(str(self.score), 1, (255, 255, 255))
screen.blit(scoreBlit, (cord, 16))
if self.score == 10:
print (winner)
exit()
def movement(self, up, down):
keys = pygame.key.get_pressed()
if keys[up]:
self.y -= self.speed
elif keys[down]:
self.y += self.speed
if self.y <= 0:
self.y = 0
elif self.y >= SCR_HEI-64:
self.y = SCR_HEI-64
def draw(self, screen):
pygame.draw.rect(screen, (255, 255, 255), (self.x, self.y, self.padWid, self.padHei))
screen.blit(bg, (640,380))
答案 2 :(得分:1)
您可以考虑在特殊表格中定义排除的国家/地区(例如ExcludedCountry)。这会将您的数据(排除的国家/地区)与您的逻辑(选择不在排除国家/地区的客户)分开。在这种情况下,您的查询可能如下所示:
select CustomerID, ContactName, Country
from Customers C
left join ExcludedCountry EC ON EC.Name = C.CustomerID
where CustomerID IS NOT NULL
或
-- may be faster than above
select CustomerID, ContactName, Country
from Customers C
where not exists (
select 1
from ExcludedCountry EC
where EC.Name = C.CustomerID)
此解决方案的优点是可以更轻松地管理您排除的项目。