0
我正在SQLite中处理大型复杂数据库。我试图创建一个查询,让我所有的繁殖母羊,即那些没有标记为出售或屠夫的。SQLite NOT LIKE无法正常工作
我使用名为alert01的字段来包含我在扫描并查找绵羊时需要注意的数据。一只待售的羊将销售或销售?在那个领域的某个地方。可以去屠夫的羊会有屠夫或屠夫吗?在那个领域。一些绵羊既在他们的警戒文本领域,因为他们可以去屠杀或出售。
这个查询将正确找到所有成年母羊,它们或者是为了出售或屠宰是目前农场:
SELECT sheep_table.sheep_id,
sheep_table.sheep_name, sheep_table.birth_date,
sire_table.sheep_name as sire_name, dam_table.sheep_name as dam_name , sheep_table.alert01
FROM sheep_table
left join sheep_table as sire_table on sheep_table.sire_id = sire_table.sheep_id
left join sheep_table as dam_table on sheep_table.dam_id = dam_table.sheep_id
WHERE sheep_table.remove_date is ''
and sheep_table.sex = 2
and sheep_table.birth_date not like "2014%"
and (sheep_table.alert01 like '%Butcher%' or sheep_table.alert01 like '%Sell%')
order by sheep_table.sheep_name asc
这一次没有找到不得出售或屠宰羊,我不不明白为什么。
SELECT sheep_table.sheep_id,
sheep_table.sheep_name, sheep_table.birth_date,
sire_table.sheep_name as sire_name,
dam_table.sheep_name as dam_name, sheep_table.alert01
FROM sheep_table
left join sheep_table as sire_table on sheep_table.sire_id = sire_table.sheep_id
left join sheep_table as dam_table on sheep_table.dam_id = dam_table.sheep_id
WHERE sheep_table.remove_date is ''
and sheep_table.sex = 2
and sheep_table.birth_date not like "2014%"
and (sheep_table.alert01 not like '%Butcher%' or sheep_table.alert01 not like '%Sell%')
order by sheep_table.sheep_name asc
它让几乎所有的羊只有消除那些在该领域alert01既卖和屠夫。
我完全失去了,对我来说,第二个查询只是第一个的补充,所以我无法弄清楚为什么它不能按我期望的那样工作。
谢谢!我很确定我在做一些愚蠢的事情非常感谢! –
OogieM
2014-09-06 19:43:09