sql - 获取所有超过 25 个字符的记录 (LENGTH(hcp.phone_number) > 25)
问题描述
我试图根据这个条件从我的查询中获取所有记录但没有成功:
(LENGTH(hcp.phone_number) > 25)
实际上我正在使用这个条件:
CASE WHEN LENGTH(hcp.phone_number) > 25 then null else hcp.phone_number END
但是,对于单个帐号,当hcp.phone_number字段大于 25 时,它只会向我显示 NULL。
我的查询工作正常,但我想修改它以获取符合此条件的所有帐号:
LENGTH(hcp.phone_number) > 25
这是我的查询:
SELECT
hp.party_name
, hca.account_number
, hca.cust_account_id
-- , hcsu.LOCATION customer_site_name
, hcas.cust_acct_site_id
, hcp.phone_number
, hcp.email_address
, CASE WHEN LENGTH(hcp.phone_number) > 25 then null else hcp.phone_number END
, hl.address1
, hl.address2
, hl.address3
, hl.address4
, hl.city
, hl.province
, hl.postal_code
, hcas.status as hcas_status
, DECODE( hcas.attribute5, 'PUP', 'Y', 'N' )
, hca.status as hca_status
FROM apps.hz_cust_accounts hca
INNER JOIN apps.hz_cust_acct_sites_all hcas ON hca.cust_account_id = hcas.cust_account_id
INNER JOIN apps.hz_party_sites hps ON hcas.party_site_id = hps.party_site_id
INNER JOIN apps.hz_locations hl ON hps.location_id = hl.location_id
INNER JOIN apps.hz_parties hp ON hps.party_id = hp.party_id
LEFT JOIN (
SELECT
owner_table_id
, max(case when contact_point_type = 'PHONE' then phone_number end) phone_number
, max(case when contact_point_type = 'EMAIL' then email_address end) email_address
FROM hz_contact_points
WHERE status = 'A'
AND primary_flag = 'Y'
AND owner_table_name = 'HZ_PARTY_SITES'
AND contact_point_type IN ('EMAIL','PHONE')
GROUP BY
owner_table_id
) hcp ON hcas.party_site_id = hcp.owner_table_id
WHERE hcas.status = 'A'
AND hps.status = 'A'
AND hca.status = 'A'
AND hca.account_number = ''
;
你能帮我解决这个问题吗?
解决方案
我认为您应该将您选择的列更改为此
, CASE WHEN LENGTH(hcp.phone_number) > 25 then hcp.phone_number END
并删除条件AND hca.account_number = ''
如果您想在结果中过滤掉所有使用 LENGTH(hcp.phone_number) <= 25 记录的内容,请在WHERE
子句中添加条件:AND LENGTH(hcp.phone_number) > 25
。
推荐阅读
- javascript - 根据其大小将空间划分为给定数量的单元格
- angular - 托管在 AWS 重定向上的 Angular 应用程序在 S3 之前拒绝访问云端
- c# - 执行自定义 MS CRM 8.2 工作流操作后出现不可能的结果
- c++ - 在类中使用后的 C++ 枚举声明
- node.js - React Native(Expo)将图像发送到节点(数据库Postgres)
- python - 当 array2 得分小于 10 时,求 array1 得分的平均值
- javascript - 使用 React 的基于 API 的搜索
- powershell - Powershell 导出结果到 xlsx 文件
- javascript - 如果加载大尺寸的形状文件数据,传单上的地图会冻结
- python - Pandas:按组条件滚动计数,计算当前观察出现在另一列的次数