COUNT(*) As num
COUNT(*) As num函数返回指定列的值的数目(NULL 不计入),完成后,以num为列头,仅返回一行数据,即数据量
# 例如算pv
SELECT COUNT(*) as pv
FROM statistic
# 例如算uv(被过滤重复后的)
SELECT COUNT(DISTINCT deviceid) as uv
FROM statistic
# 两个一起的话(这样是可以的,因为只是一行)
SELECT
COUNT(*) as pv,
COUNT(DISTINCT deviceid) as uv # DISTINCT是去重的意思
FROM statistic
GROUP的作用?
根据某一列的数据(例如day),将聚合成一行的数据(例如COUNT)拆分成多行(每天的pv)
SELECT
app, # app字段是不同app种类
COUNT(*) as pv,
COUNT(DISTINCT deviceid) as uv
FROM statistic
GROUP BY app
如何查看一个列表中有什么样的数据(去重查看结果)?
SELECT DISTINCT deviceid
FROM statistic