이 글은 MySQL에서 일반적으로 사용되는 연산자와 일반적인 기능의 사용법 및 예를 요약한 내용입니다. 필요한 친구는 이를 참조할 수 있습니다.
먼저 예를 살펴보겠습니다.
use test; create table `employee`( emp_no int unsigned, emp_name varchar(30), emp_sex varchar(3), emp_age tinyint unsigned, sal double, history datetime ); insert into employee values(1, '张三', '男', 18, 5000, '2012-04-23'), (2, '李四', '男', 27, 4500, '2013-05-23'), (3, '王五', '男', 23, 4700, '2012-04-21'), (4, '子龙', '男', 19, 3800, '2011-03-04'), (5, '李白', '男', 15, 6200, '2015-09-09'), (6, '刘备', '男', 28, 2500, '2016-02-11'), (7, '吕布', '男', 21, 6000, '2010-10-18'), (8, '尚香', '女', 16, 4500, '2011-09-26'), (9, '小乔', '女', 15, null, '2013-07-05'), (10, '大乔', '女', 16, 5000, '2017-09-01');
일반적으로 사용되는 연산자:
1: 같음 ( = )
select * from employee where sal = 3800; select * from employee where sal = null; --这里查询不到为null的数据
2: 같음 ( )
select * from employee where sal <=> 3800; select * from employee where sal <=> null; --这里可以查询到为null的数据
3: is 판단 (null)
select * from employee where sal is null; select * from employee where sal is not null;
4: Null 값 판단에는 isnull()도 사용할 수 있습니다.
select * from employee where isnull(sal); select * from employee where !isnull(sal);
5: 최소와 최대 사이의 간격(사이) 내 ps: 닫힌 간격입니다
select * from employee where sal between 4500 and 5000;
6: 이내 간격
select * from employee where sal not between 4500 and 5000; --null不为包括进去
7 : and and or
select * from employee where sal not between 4500 and 5000 or sal is null; select * from employee where sal = 4500 and emp_sex = '女';
8: 보다 작음(), 작거나 같음(=)
select * from employee where sal >= 4500;
<span style="font-family: " microsoft yahei sans gb helvetica neue>…é»', 타호마, Arial, 산세리프;">***** ************************************ **************** ********************************** ***************** ******</span><code><span style="font-family: " microsoft yahei sans gb helvetica neue tahoma arial sans-serif>***************************************************************************************************************</span><br>
수학적 함수
1: rand();
select rand() from dual; --dual是一个伪表 select 1+1 from dual; select rand(); --可以简写
2: 최소값(값1, 값2, ...)은 최소값을 반환합니다
select least(54,76,4,65,76,87,87,56,65,654,45,23,1,76); select least(54,76,4,65,76,87,87,56,65,654,45,23,1,76) as min_value; --列名可以起一个别名
3: 최대값(값1, 값2, ...) 최대값을 반환합니다.
select greatest(54,76,4,65,76,87,87,56,65,654,45,23,1,76);
4: 라운드(M, D ); M의 반올림된 값을 반환합니다. D는 유지할 소수 자릿수를 나타냅니다. 기본값은 0
select round(1.69); select round(1.69, 1);
5입니다. abs() 절대값
select 5-10; select abs(5-10);
***** ********************* ***************************** ********************** **************************** ********
집계 함수
1: avg();
select * from employee where sal >= 6000; select avg(sal) from employee where sal >= 6000;
2: count()
select count(*) from employee; select count(emp_name) from employee; select count(sal) from employee; --打印9 这里会忽略null值 select count(*) from employee where sal >= 4000; select count(*) from employee where sal <= 4000 or sal is null;
3: sum()
select sum(sal) from employee where sal >= 6000;
4: min()
select min(sal) from employee;
5: max()
select max(sal) from employee;
******** ************************** ************************* ************************* ************************** ******
날짜 함수
1: 현재 날짜와 시간을 가져옵니다
select now(), sysdate(), current_timestamp(); select now(6), sysdate(6), current_timestamp(6); ps: now(), current_timestamp();没有区别, 表示sql开始执行时的时间 sysdate()表示这个函数开始时间
2: 현재 날짜 가져오기
select curdate(); --只有年月日
3: 현재 시간 가져오기
select curtime(); --只有时分秒
4: 날짜 더하기 연산 date_add
select history, date_add(history, interval '1 12:10' day_minute) from employee; --date_add(history, interval '1 12:10' day_minute) select history, date_add(history, interval '1-1' year_month) from employee; --date_add(history, interval '1-1' year_month) select history, date_add(history, interval '1' second) from employee; --date_add(history, interval '1' second)
5: 날짜 빼기 연산 data_sub
select history, date_sub(history, interval '1-1' year_month) from employee;
6: 날짜 차이 계산
select history, sysdate(), datediff(sysdate(), history) from employee; --以天数来表示
7: 날짜의 지정된 부분 가져오기(날짜를 지정된 형식으로 변환) date_format()
select history, date_format(history, '%Y年%m月%d号') from employee; select history, date_format(history, '%d号') from employee; select history, date_format(history, '%Y年%m月%d号 %H时%i分%s秒') from employee;
8: 요일 계산 for a date
select history, dayname(history) from employee;
9: 중국어 날짜 문자열을 날짜로 변환 str_to_date()
insert into employee values(11, '张飞', '男', 22, 3000, '2017年02月01号'); --报错 insert into employee values(11, '张飞', '男', 22, 3000, str_to_date('2017年02月01号', '%Y年%m月%d号 %H时%i分%s秒'));
직원 값에 삽입(12, 'Second Brother', 'Male', 22, 3000, str_to_date('February 01 , 2017, 23:02:02', '%Y년 %m 월 %d 숫자 %H 시 %i 분 %s 초'));
직원 값에 삽입(12, '둘째', '남자', 22, 3000, str_to_date('2017년 2월 1일 11:02:02', '%Y년 %m 월 %d 숫자 %h 시간% i 분 %s 초'));
ps: h이면 12시간을 의미하고 H가 크면 24시간을 의미합니다.
문자열 함수
1: left(str, len) return 문자열 str의 왼쪽 끝은 len 문자입니다
select left('abcdefg', 5);
2: 길이 ()
select length('abcdefg');
3: lower(str)은 소문자 문자열 str
select lower('HELLO');
4를 반환합니다. substring()은 부분 문자열, 두 번째 문자열을 가져옵니다. 매개 변수는 가로채기 시작 위치이고 세 번째 매개 변수는 가로채기
select substring('helloworld',2,3);
5: concat() 문자열 연결
select concat(emp_name, '员工') from employee;
6: replacement(replace
select replace(emp_name, '李', '老') from employee where emp_name = '李四';
위 내용은 MySQL 연산자 및 함수 요약의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

MySQL은 초보자가 데이터베이스 기술을 배우는 데 적합합니다. 1. MySQL 서버 및 클라이언트 도구를 설치하십시오. 2. SELECT와 같은 기본 SQL 쿼리를 이해하십시오. 3. 마스터 데이터 작업 : 데이터를 만들고, 삽입, 업데이트 및 삭제합니다. 4. 고급 기술 배우기 : 하위 쿼리 및 창 함수. 5. 디버깅 및 최적화 : 구문 확인, 인덱스 사용, 선택*을 피하고 제한을 사용하십시오.

MySQL은 테이블 구조 및 SQL 쿼리를 통해 구조화 된 데이터를 효율적으로 관리하고 외래 키를 통해 테이블 간 관계를 구현합니다. 1. 테이블을 만들 때 데이터 형식을 정의하고 입력하십시오. 2. 외래 키를 사용하여 테이블 간의 관계를 설정하십시오. 3. 인덱싱 및 쿼리 최적화를 통해 성능을 향상시킵니다. 4. 데이터 보안 및 성능 최적화를 보장하기 위해 데이터베이스를 정기적으로 백업 및 모니터링합니다.

MySQL은 웹 개발에 널리 사용되는 오픈 소스 관계형 데이터베이스 관리 시스템입니다. 주요 기능에는 다음이 포함됩니다. 1. 다른 시나리오에 적합한 InnoDB 및 MyISAM과 같은 여러 스토리지 엔진을 지원합니다. 2.로드 밸런싱 및 데이터 백업을 용이하게하기 위해 마스터 슬레이브 복제 기능을 제공합니다. 3. 쿼리 최적화 및 색인 사용을 통해 쿼리 효율성을 향상시킵니다.

SQL은 MySQL 데이터베이스와 상호 작용하여 데이터 첨가, 삭제, 수정, 검사 및 데이터베이스 설계를 실현하는 데 사용됩니다. 1) SQL은 Select, Insert, Update, Delete 문을 통해 데이터 작업을 수행합니다. 2) 데이터베이스 설계 및 관리에 대한 생성, 변경, 삭제 문을 사용하십시오. 3) 복잡한 쿼리 및 데이터 분석은 SQL을 통해 구현되어 비즈니스 의사 결정 효율성을 향상시킵니다.

MySQL의 기본 작업에는 데이터베이스, 테이블 작성 및 SQL을 사용하여 데이터에서 CRUD 작업을 수행하는 것이 포함됩니다. 1. 데이터베이스 생성 : createAbasemy_first_db; 2. 테이블 만들기 : CreateTableBooks (idintauto_incrementprimarykey, titlevarchar (100) notnull, authorvarchar (100) notnull, published_yearint); 3. 데이터 삽입 : InsertIntobooks (Title, Author, Published_year) VA

웹 응용 프로그램에서 MySQL의 주요 역할은 데이터를 저장하고 관리하는 것입니다. 1. MySQL은 사용자 정보, 제품 카탈로그, 트랜잭션 레코드 및 기타 데이터를 효율적으로 처리합니다. 2. SQL 쿼리를 통해 개발자는 데이터베이스에서 정보를 추출하여 동적 컨텐츠를 생성 할 수 있습니다. 3.mysql은 클라이언트-서버 모델을 기반으로 작동하여 허용 가능한 쿼리 속도를 보장합니다.

MySQL 데이터베이스를 구축하는 단계에는 다음이 포함됩니다. 1. 데이터베이스 및 테이블 작성, 2. 데이터 삽입 및 3. 쿼리를 수행하십시오. 먼저 CreateAbase 및 CreateTable 문을 사용하여 데이터베이스 및 테이블을 작성한 다음 InsertInto 문을 사용하여 데이터를 삽입 한 다음 최종적으로 SELECT 문을 사용하여 데이터를 쿼리하십시오.

MySQL은 사용하기 쉽고 강력하기 때문에 초보자에게 적합합니다. 1.MySQL은 관계형 데이터베이스이며 CRUD 작업에 SQL을 사용합니다. 2. 설치가 간단하고 루트 사용자 비밀번호를 구성해야합니다. 3. 삽입, 업데이트, 삭제 및 선택하여 데이터 작업을 수행하십시오. 4. Orderby, Where and Join은 복잡한 쿼리에 사용될 수 있습니다. 5. 디버깅은 구문을 확인하고 쿼리를 분석하기 위해 설명을 사용해야합니다. 6. 최적화 제안에는 인덱스 사용, 올바른 데이터 유형 선택 및 우수한 프로그래밍 습관이 포함됩니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.
