数据库基础

2021-11-09  本文已影响0人  1baibai
1. 数据库(DDL)

create database if not exists 1baibai charset utf8;
drop database if exists 1baibai;
alter database 1baibai character set utf8;
2. 表(DDL)

CREATE TABLE `job` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `job_name` varchar(255) DEFAULT NULL,
  `create_time` datetime DEFAULT NULL,
  `create_people` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
show tables;
 desc job;
show create table job;
3. 数据操作(DML)
INSERT INTO jobs (job_name, create_people, description) VALUES ('iOS', 'Bill', 'iOS开发招聘');

INSERT INTO jobs VALUES (2, 'Java', 'linda', 'Java开发招聘');
UPDATE jobs SET job_name = 'android' WHERE id = 2;
DELETE FROM jobs WHERE id = 3;
4. 查询
SELECT * FROM jobs;
SELECT job_name, create_people FROM jobs;
SELECT DISTINCT job_name, create_people FROM jobs;
5. 聚合函数
  1. 列函数统计(不为NULL)
SELECT COUNT(des) FROM jobs;

2.最大值查询

SELECT MAX(age) FROM jobs;

3.最小值查询

SELECT MIN(age) FROM jobs;

4.和查询

SELECT SUM(age) FROM jobs;
  1. 平均值查询
SELECT AVG(age) FROM jobs;
6.分组查询
SELECT job_name, COUNT(*) FROM jobs GROUP BY id;
7.限定查询
SELECT * from jobs LIMIT 1,5;
上一篇下一篇

猜你喜欢

热点阅读