[英]mysql select column value from another column
I have a mysql query我有一个 mysql 查询
select host, domain from table
Output:
host domain
host1.abc.com abc.com
host2.abc.com null
I want to change the query so that I get domain
value from the first column by stripping out the host
part.我想更改查询,以便通过剥离host
部分从第一列中获取domain
值。 I don't want to query the domain
value from the table because some of it is blank我不想从表中查询domain
值,因为其中一些是空白的
This way domain for host - host2.abc.com
would be abc.com
这样host - host2.abc.com
域host - host2.abc.com
将是abc.com
DROP TABLE bleach;
CREATE TABLE bleach (`host` VARCHAR(50) NOT NULL);
INSERT INTO bleach (`host`) VALUES ('host1.abc.com');
INSERT INTO bleach (`host`) VALUES ('host29.abcdefg.com');
SELECT * FROM bleach;
SELECT `host`, SUBSTRING_INDEX(`host`,'.',-2) FROM bleach;
OUTPUT:输出:
host SUBSTRING_INDEX(`host`,'.',-2)
host1.abc.com abc.com
host29.abcdefg.com abcdefg.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.