我有一个表 Data 如下:
Name Address Country
A PO 123 AF Afghanistan
B PO 23 AFG AF
C PO IND df1 AFG
D PO 12345 USA
我想获取所有 Address 与 Country 不同的记录。在上面的例子中,我需要记录 3 (Name = C),因为 Address 有“IND”,Country 是“AFG”。
注意:
Country 可以是 ISO-2、ISO-3 或描述(例如“IN”、“IND”或“India”)Address 可能包含也可能不包含国家/地区名称 - 如果包含,则可能是 ISO-2、ISO-3 或说明。Country 详细信息存储在单独的 Country 表中,所有国家都存储为 -
Id | Iso2 | Iso3 | Description
我确定,
在此先感谢您的帮助。
最佳答案
您是否希望在结果中包含美国行?
MySQL 5.6 架构设置:
查询 1:
select *
from Data
inner join country
on (
Data.country = country.Iso2
or Data.country = country.Iso3
or Data.country = country.Description
)
Where
Data.Address NOT like concat('%',country.Iso2,'%')
and Data.Address NOT like concat('%',country.Iso3,'%')
and Data.Address NOT like concat('%',country.Description,'%')
Results :
| Name | Address | Country | Id | Iso2 | Iso3 | Description |
|------|------------|---------|----|------|------|--------------------------|
| C | PO IND df1 | AFG | 1 | AF | AFG | Afghanistan |
| D | PO 12345 | USA | 3 | US | USA | united states of america |
查询 2:
select Data.*, country.*
from Data
inner join country
on (
Data.country = country.Iso2
or Data.country = country.Iso3
or Data.country = country.Description
)
left join country ca
on (
Data.Address like concat('%',ca.Iso2,'%')
or Data.Address like concat('%',ca.Iso3,'%')
or Data.Address like concat('%',ca.Description,'%')
)
Where
Data.Address NOT like concat('%',country.Iso2,'%')
and Data.Address NOT like concat('%',country.Iso3,'%')
and Data.Address NOT like concat('%',country.Description,'%')
and ca.id IS NOT NULL
Results :
| Name | Address | Country | Id | Iso2 | Iso3 | Description |
|------|------------|---------|----|------|------|-------------|
| C | PO IND df1 | AFG | 1 | AF | AFG | Afghanistan |
关于mysql - 列包含来自其他表列的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46344565/
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我有一个这样的哈希数组:[{:foo=>2,:date=>Sat,01Sep2014},{:foo2=>2,:date=>Sat,02Sep2014},{:foo3=>3,:date=>Sat,01Sep2014},{:foo4=>4,:date=>Sat,03Sep2014},{:foo5=>5,:date=>Sat,02Sep2014}]如果:date相同,我想合并哈希值。我对上面数组的期望是:[{:foo=>2,:foo3=>3,:date=>Sat,01Sep2014},{:foo2=>2,:foo5=>5:date=>Sat,02Sep2014},{:foo4=>4,:dat
我有一个包含多个键的散列和一个字符串,该字符串不包含散列中的任何键或包含一个键。h={"k1"=>"v1","k2"=>"v2","k3"=>"v3"}s="thisisanexamplestringthatmightoccurwithakeysomewhereinthestringk1(withspecialcharacterslike(^&*$#@!^&&*))"检查s是否包含h中的任何键的最佳方法是什么,如果包含,则返回它包含的键的值?例如,对于上面的h和s的例子,输出应该是v1。编辑:只有字符串是用户定义的。哈希将始终相同。 最佳答案
我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c
我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent
我收到格式为的回复#我需要将其转换为哈希值(针对活跃商家)。目前我正在遍历变量并执行此操作:response.instance_variables.eachdo|r|my_hash.merge!(r.to_s.delete("@").intern=>response.instance_eval(r.to_s.delete("@")))end这有效,它将生成{:first="charlie",:last=>"kelly"},但它似乎有点hacky和不稳定。有更好的方法吗?编辑:我刚刚意识到我可以使用instance_variable_get作为该等式的第二部分,但这仍然是主要问题。
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co