---
title: "MySql常用sql语句学习笔记"
author: "TimerBin"
date: "2016-08-22T10:49:18Z"
tags: []
categories: ["编程语言"]
slug: "mysql-sql"
draft: false
lastmod: "2016-08-22T10:49:18Z"
id: 2319370
url: "https://timerbin.iteye.com/blog/2319370"
---

在MySql中常用的几种查询：

 

**一、根据条件按字段分组查询，条数大于1的所有数据列表：**

```
select a.type,count(1) as sum from user  a where a.type >2 group by a.type having sum >2
```

 查询出来的结果如下所示：

![](http://dl2.iteye.com/upload/attachment/0119/4908/08f2bc64-5ed0-3cd6-908d-08e762a6efdd.jpg)  
 

**二、数据库中表时间字段与字符串:**

```
select * from user where unix_timestamp(created_time) > unix_timestamp('2016-08-16 00:00:01');
```

 使用unix\_timestamp函数对时间字符串进行转义，然后再进行判断！

具体可参考：http://timerbin.iteye.com/admin/blogs/2037840