[MySQL] 특정 문자 개수 세기 > db

본문 바로가기
사이트 내 전체검색

db

[MySQL] 특정 문자 개수 세기

페이지 정보

작성자 서방님 댓글 0건 조회 731회 작성일 17-08-31 10:03

본문

문자열 컬럼내 '@'의 갯수를 알아내려고 찾았을때 아래 구문을 쓰는 내용을 보았다.
정말이지 대한민국은 머리 좋은 사람이 많은것 같다.. ㅎㅎ
참고 페이지를 닫아서...하이튼 고맙습니다.
SELECT
SUM((CHAR_LENGTH(Paper_list)-CHAR_LENGTH(REPLACE(Paper_list,'@',''))+1))
FROM T_NewsInfo WHERE Notice_Number IN ('0999427', '0999426')
-----------------------------------------------------------------
Mysql 방법2 전체문자갯수에서 찾고자하는 문자열을 공백으로 처리한 문자열갯수를 뺌
CREATE FUNCTION getStrCount ( inputdata varchar(250), searchStr varchar(250) )
RETURNS int
BEGIN
declare q int;
set q = char_length(inputdata) - char_length(replace(inputdata,searchStr,'');
RETURN(q);
END
select getStrCount (필드 또는 문자열,'찾고자 하는 문자열') from table;
-----------------------------------------------------------------
Mssql
CREATE FUNCTION getStrCount (@inputdata nvarchar(max), @searchStr nvarchar(max) )
RETURNS int
AS
BEGIN
DECLARE @q int
SET @q = LEN(@inputdata) - LEN(REPLACE(@inputdata, @searchStr, ''))
RETURN @q
END
/********************************************************************************
* 1차 카테고리가 누락된 데이터 조회
********************************************************************************/
Select goodsno
, Left(category, 3) As 'depth1'
, Group_Concat(category) As 'cate'
, Max(Length(category)) / 3 As 'max_depth'
From gd_goods_link
Where Left(category, 3) = '005'
Group By goodsno, Left(category, 3)
Having Left(cate, 4) <> depth1+','
Select goodsno, depth1, cate, max_depth
, Sum((Char_Length(cate)-Char_Length(Replace(cate,',',''))+1)) -- 콤마 개수
From (
Select goodsno
, Left(category, 3) As 'depth1'
, Group_Concat(category) As 'cate'
, Max(Length(category)) / 3 As 'max_depth'
From gd_goods_link
Where Left(category, 3) = '005'
Group By goodsno, Left(category, 3)
Having Left(cate, 4) <> depth1+','
) As A

댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
89
어제
225
최대
1,347
전체
154,848
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.