---
title: "如果按每种类型分别查询前n条记录"
author: "tmuffamd"
date: "2017-10-18T18:52:23Z"
tags: []
categories: ["数据库"]
slug: "n"
draft: false
lastmod: "2017-10-18T18:52:23Z"
id: 2396860
url: "https://tmuffamd.iteye.com/blog/2396860"
---

SELECT * FROM coin\_shop a WHERE  
(SELECT COUNT(\*) FROM coin\_shop b WHERE b.goods\_type=a.goods\_type AND b.cs\_id&gt;a.cs\_id ) &lt;2 

 

 

这样查出来，按照goods\_type分别显示每种的前n个