---
title: "MySql count 去掉重复"
author: "wangheid"
date: "2012-03-28T14:03:11Z"
tags: []
categories: ["数据库"]
slug: "mysql-count"
draft: false
lastmod: "2012-03-28T14:03:11Z"
id: 1466212
url: "https://wangjiabei.iteye.com/blog/1466212"
---

1\.

select count(distinct CName) from Course

2\.

select count(CName) from (select distinct CName from Course) as temp

as可有可无。temp作为别名，若无则提示错误：1248 – Every derived table must have its own alias