I have a table with the following columns
source_title, country, language, source_url
I need to generate a query that will give me the following:
country, source_title count, percentage of sources
and
language, source_title count, percentage of sources
basically map the country to all sources and get the count and percentages of this mapping
not the row level data like
SELECT [source_id]
,[source_title]
,[source_url]
,[moreover]
,[country]
,[lang]
FROM [NewsDatabase].[dbo].[NewsSourcesMatch]
order by country
For example if there are 10 records where country is USA then
country count(source_title) % source_title
USA 10 10/1000 * 100
sorry everyone here is sample data
source_title source_url moreover country lang
Hadeland http://www.hadeland.net Hadeland NORWAY Norwegian
Business Wire http://www.businesswire.com Business Wire UNITED STATES English
Adelaide Now http://www.adelaidenow.com.au Adelaide Now AUSTRALIA English
MSNBC Local http://www.msnbc.msn.com MSNBC Local UNITED STATES English
UDN.com http://forum.udn.com UDN.com TAIWAN Chinese
CBS3 Philadelphia http://cbs3.com CBS3 Philadelphia UNITED STATES English
104.7 Edge Radio http://www.1047edgeradio.com 104.7 Edge Radio UNITED STATES English
so there are four from UNITED STATES so shouldnt the total percentage be 4/7* 100
You can use the OVER clause to span the entire dataset with COUNT to give total number of rows in the same query. Then you have both counts (per country and all rows) to generate the %
Should be something like:
If not, please add sample data and required output.
Or this?
Can’t test this (no SQL on this PC) but based on MSDN OVER clause