asp.net - find count of distinct values in a column -


hi trying build sql query display information on dashboard.

i have table in store sales data.my query needs find total sales in last 7 days,average , group based on region(which present in user table.) .i created temp table item sales.dashboard_items table contains particular item needs shown on dashboard.now problem need store count of each region find average sales.can 1 please help

declare @tabletest  table(itemid int,itemname varchar(100),itemdescription varchar(100),id int,itemidd int,userid int,orderdate varchar(40),qty int)  insert @tabletest  select * dashboard_items join  salesqty on salesqty.orderdate>=  convert(varchar(10) , dateadd(day,-7,getdate()),126)   , oos_dashboard_coreitems.itemid=salesqty.itemid   select distinct t.userid,u.region @tabletest t join users u on t.userid=u.userid , region not null 

above select query returns

enter image description here

how can region count above select query

    region             count  5 - sun west            2  2 - long island         3 

you need group region , use cont(*)

select region, count(*)  @tabletest group region; 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -