Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3333504
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:48:14+00:00 2026-05-17T23:48:14+00:00

I have a table with the following columns source_title, country, language, source_url I need

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:48:15+00:00Added an answer on May 17, 2026 at 11:48 pm

    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:

    SELECT  [Country]
        ,   [source_title_count] =  COUNT(*)
        ,   [source_total_count]  = COUNT(*) OVER ()
        ,   [source_percent]  = 100.0 * COUNT(*) / COUNT(*) OVER () 
    FROM [dbo].[NewsSourcesMatch]
    GROUP   BY [Country]
    
    SELECT  [lang]
        ,   [source_title_count] =  COUNT(*)
        ,   [source_total_count]  = COUNT(*) OVER ()
        ,   [source_percent]  = 100.0 * COUNT(*) / COUNT(*) OVER () 
    FROM [dbo].[NewsSourcesMatch]
    GROUP   BY [lang]
    

    If not, please add sample data and required output.

    Or this?

    SELECT  [Country]
        ,   COUNT(DISTINCT [source_title)) AS source_title_count
        ,   COUNT(*) source_country_count
        ,   100.0 * COUNT(*) / COUNT(DISTINCT [source_title)) source_country_count
    FROM [dbo].[NewsSourcesMatch]
    GROUP  BY [Country]
    

    Can’t test this (no SQL on this PC) but based on MSDN OVER clause

    SELECT  [Country]
        ,   [source_title_count] =  COUNT(*)
         --attempt 1
        ,   [source_total_count]  = COUNT(*) OVER (Country)
        ,   [source_percent]  = 100.0 * COUNT(*) / COUNT(*) OVER (Country) 
         --attempt 2
        ,   [source_total_count]  = COUNT(*) OVER (PARTITION BY Country)
        ,   [source_percent]  = 100.0 * COUNT(*) / COUNT(*) OVER (PARTITION BY Country) 
    FROM [dbo].[NewsSourcesMatch]
    GROUP   BY [Country]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that contains the following columns: ID int, DISTANCE float, EVENT
Lets say I have table with following columns 1. Client - string. 2. Profit
I have a table with following columns: ContractorId ......... INT ............. IDENTITY ContractorName ........
I have a table with the following columns in SQL Server: MEMBERID, MEMBEREMAIL, FATHEREMAIL,
I have a table with the following columns: ref_year, ref_no, inv_id, start_date, end_date The
I have a table with the following columns (I simplified it a little): PRODUCT_name
I have a table with the following columns: EntityId, EntityName, EntityProfile, ................. I want
Lets say I have a table with the following columns: Qty, INTEGER SaleDate, DATETIME
I have created a table with the following columns: ObservationId, FirstCreatedDate, description, ... ...
i have users_details table with the following columns martial_status | religion | education i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.