通过sql查询显示相同coloumn中重复值的数据

时间:2016-04-06 07:00:55

标签: mysql sql-server

我的表格如下:

site_id     customer    Date
------------------------------
xyz         Airtel      01/02/16
xyz         Idea        01/02/16
xyz         Aircel      01/02/16
abc         Aircel      01/02/16
abc         Airtel      01/02/16
abc         idea        01/02/16
pqr         idea        01/02/16
pqr         idea        01/02/16
pqr         Airtel      01/02/16

我想显示特定site_id有多少客户可用的日期数据。

2 个答案:

答案 0 :(得分:0)

select site_id,customer,date
from table_name 
where site_id =input_site_id and date =input_date 

答案 1 :(得分:0)

这将按位置为您提供不同客户的计数

select site_id, date, count(distinct customer)
from   yourtable
group by site_id, date

如果您想了解特定网站& date,在WHERE子句中指定条件。示例:

select site_id, date, count(distinct customer)
from   yourtable
where  site_id = 'xyz'
and    date    = '20160201'
group by site_id, date