Function 사용 예제
DROP FUNCTION IF EXISTS getTotals # CREATE FUNCTION getTotals(d_id VARCHAR(50), start_date VARCHAR(30), end_date VARCHAR(30)) RETURNS INT(10) BEGIN DECLARE totals INT(10); SET totals = ( SELECT COUNT(*) AS total FROM device_info WHERE DATE_FORMAT(CONVERT_TZ(device_info.create_time, "UTC", "Asia/Seoul"), "%Y-%m-%d %H:%i:%S")>=start_date AND DATE_FORMAT(CONVERT_TZ(device_info.create_time, "UTC", "Asia/Seoul"), "%Y-%m-%d %H:%i:%S")<=end_date AND device_info.device_id = d_id ); RETURN totals; END # SELECT getTotals("2012-11-26 00:00:00", "2012-12-26 23:00:00");
구분자를 이용한 Explode 사용 방법
select substring_index(컬럼명,'구분자',1)as col1,substring_index(컬럼명,'구분자',-1)as col2 from 테이블;