Mysql notes
1. 数据库操作 database management
create database sampleDatabase; --创建数据库sampleDatabase
show databases; --显示已有的数据库
use sampleDatabase; --开始使用sampleDatabase
drop database sampleDatabase; --删除
2. 表操作 table management
create table sampletable(
id int(10) not null auto_increment;
val varcahr(50) ;
primary key (id)
); --创建表sampletable
--改变表结构操作alter
alter table sampletable add column start_time date after id; --在id列后添加start_time列
alter table sampletable change column val val varchar(100) not null; --更改var列的设置
alter table sampletable drop column start_time --删除start_time列
alter table sampletable rename to sample; --表名改为sample
3. 选择某列第n大的值
select * from sampleTable --选择表sampleTable
order by targetColumn desc --按照targetColum降序排列
limit n-1,1 --选择第n行的数据(注意这里n-1要为计算后的常量,否则出错)
--function definition
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
declare m int;
set m = n-1;
RETURN (select distinct salary from Employee order by salary desc limit m,1);
END
4. 聚合函数
select avg(columnA), sum(columnA), count(columnA), min(columnA), max(columnA)
from sampleTable;
5. DATE操作
select datediff('2011-08-17','2011-08-08') --前面日期-后面日期 = 9 days
select (now() - INTERVAL 1 DAY) 'NOW - 1 day',
now() 'now ',
(now() + INTERVAL 1 DAY) 'NOW + 1 day';
Reference: Mysql Tutorial
Mysql notes的更多相关文章
- zabbix low-level discovery 监控mysql
当一台服务器上MySQL有多个实例的时候,MySQL占用多个不同端口.利用zabbix的low-level discovery可以轻松监控. 思路参考:http://dl528888.blog.51c ...
- django model Meta选项
可用的 Meta 选项 abstract Options.abstract 如果 abstract = True ,这个 model 就是一个 抽象基类 . app_label Options.app ...
- SQL注入备忘单
Find and exploit SQL Injections with free Netsparker SQL Injection Scanner SQL Injection Cheat Sheet ...
- Django 2.0.1 官方文档翻译: 文档目录 (Page 1)
Django documentation contents 翻译完成后会做标记. 文档按照官方提供的内容一页一页的进行翻译,有些内容涉及到其他节的内容,会慢慢补上.所有的翻译内容按自己的理解来写,尽量 ...
- [MySQL Reference Manual]14 InnoDB存储引擎
14 InnoDB存储引擎 14 InnoDB存储引擎 14.1 InnoDB说明 14.1.1 InnoDB作为默认存储引擎 14.1.1.1 存储引擎的趋势 14.1.1.2 InnoDB变成默认 ...
- MySQL 5.7 学习:新增配置参数
背景: 继上次介绍 初识 MySQL 5.6 新功能.参数完之后,刚好MySQL 5.7又GA了,在官方测试里看到,MySQL5.7在功能.性能.可用性.安全和监控上又提升了很高.现在看看和MySQL ...
- Centos7搭建需要mysql的网站
1.在centos7上安装好http.php.php-mysql服务 php-mysql是用来链接的工具 2.在centos5上yum安装mysql 注意在搭建本地yum源时把校验关闭,不然安装不上 ...
- 许愿墙的搭建(基于Apache+php+mysql)
一.准备部分:CentOS 7 , Linux 文本 各自配置好环境 二. CentOS 7准备如下: yum install httpd -y #安装httpd yum install php ...
- MySQL for Visual Studio Version
MySQL for Visual Studio Version Connector/Net Version Supported Visual Studio Version Supported MySQ ...
随机推荐
- 设置更新源和下载ferret
kali无法定位软件包 解决: deb http://http.kali.org/kali kali-rolling main non-free contrib kali可用的官方更新源(cd /et ...
- Abundant Resources
https://github.com/vhf/free-programming-books/blob/master/free-programming-books-zh.md
- 移动端 触摸事件 ontouchstart、ontouchmove、ontouchend、ontouchcancel
1.Touch事件简介 pc上的web页面鼠 标会产生onmousedown.onmouseup.onmouseout.onmouseover.onmousemove的事件,但是在移动终端如 ipho ...
- scp 从远程拷贝文件不需要密码
执行这一句,弹出来要你输入密码,输入一次后,以后再 scp 远程机的文件 再也不需要密码了 ssh-copy-id myusername@8.8.8.8
- Excel 导入 导出 Microsoft
导出: private void exportExcel() { if (saveFileDialog1.ShowDialog() == DialogResult.OK) { Application. ...
- 夺命雷公狗----Git---6---GitHub基本使用
github不是git. git是一个版本控制系统,是一个版本控制软件,从而完善共同开发... github是一个网站,基于git的,主要作用是代码托管的.... 托管的几层含义如下: 1:将自己平常 ...
- 多线程迭代之——LINQ to TaskQuery
平时经常会迭代集合,如果数据多的话会很耗时. 例子: , , }; list.ForEach(a => DoSomething(a)); void DoSomething(int a) { // ...
- 自定义置顶TOP按钮
简述一下,分为三个步骤: 1. 添加Html代码 2. 调整Css样式 3. 添加Jquery代码 具体代码如下: <style type="text/css"> #G ...
- view向上滚动
之前本来是打算做TextView垂直向上滚动的,后来发现一位大神做得很好,https://github.com/sfsheng0322/MarqueeView 孙福生大神,然后自己要用到多个View向 ...
- LeetCode:461. Hamming Distance
package BitManipulation; //Question 461. Hamming Distance /* The Hamming distance between two intege ...