sql - The SUM of an aggregate COUNT function -


i want create query calculate percentage sales of overall policies in database. policies split under 2 separate headings

  • ul
  • nl

the code want should display

  • product name
  • number of policies sold
  • policies sold per product percentage of overall number of policies sold.

i have made few attempts @ scripting code (please see below) cannot them run correctly.

syntax 1:

select b.product_name, b.policies_sold, 100.00*(b.policies_sold/sum(b.policies_sold)) as'perc_sales' ( select a.product_name, count(a.product_name)  'policies_sold'          (select product_name [atlantis\jjudge]. [all_policies_201706_nl]     union      select product_name [atlantis\jjudge]. [all_policies_201706_ul])a group product_name)b ; 

syntax 2:

select a.product_name, a.[policies sold], 100.00*(a.[policies sold]/sum(a.[policies sold]))       (select product_name, count(*) 'policies sold'from  [atlantis\jjudge].[all_policies_201706_nl] group product_name     union      select product_name, count(*) 'policies sold'  [atlantis\jjudge].[all_policies_201706_ul] group   product_name)a ; 

syntax 3:

select b.product_name, count(b.product_name)  'policies_sold', 100.00* (count(b.product_name)/sum(select(product_name))          (select count(*) 'policy_count' [atlantis\jjudge].[all_policies_201706_nl]     union     select count(*) 'policy_count' [atlantis\jjudge].[all_policies_201706_ul])a)) 'perc_sales'          (select product_name [atlantis\jjudge]. [all_policies_201706_nl]     union      select product_name [atlantis\jjudge]. [all_policies_201706_ul])b group product_name; 

i think want window function. modify syntax 1 first line as:

select      b.product_name,      b.policies_sold,      100.00*b.policies_sold/sum(b.policies_sold) on () 'perc_sales' 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -