sql-server - SQL用值列表替换null
问题描述
我有一张City
和StatePopulation
桌子
CREATE TABLE dbo.City
(
Code INT,
CityName VARCHAR(30)
)
INSERT INTO CITY (CODE, CityName)
select 1, 'Woodside'
union
select 2, 'Sunnyside'
union
select 3, 'Flushing'
union
select 4, 'Elmhurst'
union
select 5, 'ForestHills'
union
select 6, 'Manhattan'
union
select 7, 'Atlanta'
union
select 8, 'Alpharetta'
union
select 9, 'Johns Creek'
CREATE TABLE DBO.CityPopulation
(
StateCode VARCHAR(10),
CityCode INT,
PopulationCount INT
)
INSERT INTO DBO.CityPopulation (StateCode, CityCode, PopulationCount)
SELECT 'NY', 1, 1000
UNION
SELECT 'NY', 2, 1500
UNION
SELECT 'NY', 3, 2500
UNION
SELECT 'NY', 4, 3000
UNION
SELECT 'NY', 5, 3500
UNION
SELECT 'NY', 6, 4000
UNION
SELECT 'GA', 7, 5500
UNION
SELECT 'GA', 8, 1200
UNION
SELECT 'GA', 9, 1900
CREATE TYPE dbo.UDTT_StateType AS TABLE (StateCode VARCHAR(10), CityCode INT)
DECLAR @State dbo.UDTT_StateType
INSERT INTO @State (StateCode, CityCode)
select 'NY', null
union
select 'GA', 8
现在我需要返回与 and 匹配的值的行,但是CityPopulation
当' NY' 和为空时,我需要返回 CityCode 1 和 2 的数据UDTT_StateType
StateCode
CityCode
StateCode
City Code
谁能帮我写这个查询,好吗?
解决方案
推荐阅读
- r - 如何根据 R 中的循环删除所有行
- azure - 使用客户端 ID 和客户端密码以及图形 API 获取访问令牌以从 Azure 拉取用户组所需的范围
- ldap-query - 在 FreeIPA 服务器上测试组成员身份
- python - Pymongo在insert_many之后在原始数组中插入_id。如何避免插入_id?
- regex - unix - 文件中的模式匹配
- pandas - 错误:float() 参数必须是字符串或数字,而不是 'datetime.date'
- c - C - 结构字符串元素被连接起来
- c# - 编译器为纯静态方法体生成类
- c# - 具有空间数据的 Hololens 视频流
- c# - 处理 _Partial Page 的请求时发生未处理的异常