我有一列包含这样的字符串:
Traceback (most recent call last):
File "hello.py", line 11, in <module>
founders = soup.select('.founders section .section with_filler
with_editable_regions dsss17 startups-show-sections ffs70 founders _a _jm
.dsr31 startup_roles fsp87 startup_profile_group _a _jm .larger roles
role')
File "C:\Users\nandi\Anaconda3\lib\site-packages\bs4\element.py", line
1477, in select
'Unsupported or invalid CSS selector: "%s"' % token)
ValueError: Unsupported or invalid CSS selector: "_a"
和我使用的查询:
+-------------------+
| type |
+-------------------+
|cashback_percentage|
| cashback_fix |
| fix |
+-------------------+
但是我得到了这样的结果:
SELECT CONCAT(UCASE(LEFT(replace(type, " ", "_"), 1))) as new_type from mytable;
我希望结果删除下划线并将其替换为空格,并在每个单词上将每个首字母大写,如下所示:
+-------------------+
| new_type |
+-------------------+
| C |
| C |
| F |
+-------------------+
答案 0 :(得分:1)
您在正确的轨道上。这种方法是先进行串联,对第一个字母进行大写,然后对整个字符串进行替换,以将下划线与空格交换。
SELECT
type,
REPLACE(CONCAT(UPPER(LEFT(type, 1)), SUBSTRING(type, 2)), '_', ' ') AS output
FROM yourTable;
答案 1 :(得分:0)
您可以使用Replace
select replace(type, '_', ' ') from tb
要大写,您可以使用自定义功能
CREATE FUNCTION CAP_FIRST (input VARCHAR(255))
RETURNS VARCHAR(255)
DETERMINISTIC
BEGIN
DECLARE len INT;
DECLARE i INT;
SET len = CHAR_LENGTH(input);
SET input = LOWER(input);
SET i = 0;
WHILE (i < len) DO
IF (MID(input,i,1) = ' ' OR i = 0) THEN
IF (i < len) THEN
SET input = CONCAT(
LEFT(input,i),
UPPER(MID(input,i + 1,1)),
RIGHT(input,len - i - 1)
);
END IF;
END IF;
SET i = i + 1;
END WHILE;
RETURN input;
END;
用法
select CAP_FIRST(replace(type, '_', ' ')) from tb