假设你的意思列标题,然后给第一个字段在查询的别名,如:
select email_address AS Whatever
from company_digital
where email_address is not null
and email_address is not null
and hash_id >=700 and hash_id <800
union
select email_address_2
from company_digital
where email_address_2 is not null
and email_address_2 is not null
and hash_id >=700 and hash_id <800
union
select email_address_3
from company_digital
where email_address_3 is not null
and email_address_3 is not null
and hash_id >=700 and hash_id <800;
这将输出:
| Whatever |
_____________
[email protected]
[email protected]
_________________
或者
select email_address AS ' '
from company_digital
where email_address is not null
and email_address is not null
and hash_id >=700 and hash_id <800
union
select email_address_2
from company_digital
where email_address_2 is not null
and email_address_2 is not null
and hash_id >=700 and hash_id <800
union
select email_address_3
from company_digital
where email_address_3 is not null
and email_address_3 is not null
and hash_id >=700 and hash_id <800;
这将输出:
| |
_____________
[email protected]
[email protected]
_________________
编辑清除代码:
SELECT email_address AS ' '
FROM company_digital
WHERE email_address IS NOT NULL
AND hash_id BETWEEN 700 AND 800
UNION
SELECT email_address_2
FROM company_digital
WHERE email_address_2 IS NOT NULL
AND hash_id BETWEEN 700 AND 800
UNION
SELECT email_address_3
FROM company_digital
WHERE email_address_3 IS NOT NULL
AND hash_id BETWEEN 700 AND 800;
,或者根据您的数据......
SELECT CASE WHEN email_address IS NOT NULL
THEN email_address
WHEN email_address_2 IS NOT NULL
THEN email_address_2
WHEN email_address_3 IS NOT NULL
THEN email_address_3
END AS ' '
FROM company_digital
WHERE hash_id BETWEEN 700 AND 800
你想跳过第一个结果行或只显示没有列标题的结果? – tommyO
是的,列标题 –
这不是一个SQL语言问题。这将取决于具体使用哪个SQL客户端来运行查询。哪一个?您应该考虑在您的问题中添加该标签。 – tommyO