3 回答
TA贡献1891条经验 获得超3个赞
SELECT title, description, ROUND ( ( LENGTH(description) - LENGTH( REPLACE ( description, "value", "") ) ) / LENGTH("value") ) AS count FROM <table>
TA贡献1825条经验 获得超6个赞
select TITLE, (length(DESCRIPTION )-length(replace(DESCRIPTION ,'value','')))/5 as COUNT FROM <table>
SQL Fiddle演示
TA贡献1815条经验 获得超13个赞
请让我知道它是否对你的MySQL也有效。
在sql server中,这是答案。
Declare @t table(TITLE VARCHAR(100), DESCRIPTION VARCHAR(100))
INSERT INTO @t SELECT 'test1', 'value blah blah value'
INSERT INTO @t SELECT 'test2','value test'
INSERT INTO @t SELECT 'test3','test test test'
INSERT INTO @t SELECT 'test4','valuevaluevaluevaluevalue'
SELECT TITLE,DESCRIPTION,Count = (LEN(DESCRIPTION) - LEN(REPLACE(DESCRIPTION, 'value', '')))/LEN('value')
FROM @t
结果
TITLE DESCRIPTION Count
test1 value blah blah value 2
test2 value test 1
test3 test test test 0
test4 valuevaluevaluevaluevalue 5
因此,MySQL中的等效查询应该是
SELECT TITLE,DESCRIPTION, (LENGTH(DESCRIPTION) - LENGTH(REPLACE(DESCRIPTION, 'value', '')))/LENGTH('value') AS Count
FROM <yourTable>
请让我知道它是否对你的MySQL也有效。
添加回答
举报