0

I am trying to get my percentages to equal 100%. As of right now they far surpass 100%.

I need to account for the percentages in two different tables, ua_money_allocation and ua_expenses_by_school.

I am not sure how I can add these two tables in properly without getting:

error code 1241, "Operand should contain 1 column(s)"

Query:

SELECT 'Salaries and Wages' as 'Category',
CONCAT('$',ROUND(SUM(Value_USD),0)) AS 'Amount',
CONCAT('$',ROUND(SUM(Value_USD)/(COUNT(DISTINCT ua_money_allocation.school_ID_FK)))) AS 'Mean',
(ROUND(SUM(ua_money_allocation.Value_USD)/
    (SUM(ua_money_allocation.Value_USD)*100,1 + 
    SUM(ua_expenses_by_school.Amount_USD)))) AS 'Percent of Total',
CONCAT('$',ROUND(Min(Value_USD),0)) AS 'Minimum',
CONCAT('$',ROUND(MAX(Value_USD),0)) AS 'Maximum'
FROM ua_money_allocation
Join ua_expenses_by_school
ON ua_money_allocation.school_ID_FK = ua_expenses_by_school.school_id_fk
WHERE ua_money_allocation.Report_yr='2015'
AND Value_USD !=0
AND Amount_USD!=0
AND Spending_Activity='Total Spent'

UNION ALL

SELECT Category,
CONCAT('$',ROUND(SUM(Amount_USD),0)) AS 'Amount',
CONCAT('$',ROUND(SUM(Amount_USD)/(COUNT(DISTINCT ua_expenses_by_school.school_ID_FK)))) AS 'Mean',
(ROUND(SUM(ua_expenses_by_school.Amount_USD)/
    (SUM(ua_expenses_by_school.Amount_USD)*100,1 + 
       SUM(ua_money_allocation.Value_USD)))) AS 'Percent of Total',
CONCAT('$',ROUND(Min(Amount_USD),0)) AS 'Minimum',
CONCAT('$',ROUND(MAX(Amount_USD),0)) AS 'Maximum'
FROM ua_expenses_by_school
JOIN ua_money_allocation
ON ua_expenses_by_school.school_id_fk = ua_money_allocation.school_ID_FK
WHERE ua_expenses_by_school.Report_yr='2015'
AND Amount_USD !=0
AND Value_USD !=0
AND Spending_Activity='Total Spent'
group by category

1 Answer 1

0

Stare at this:

/
(   SUM(ua_expenses_by_school.Amount_USD) * 100 ,
1 + SUM(ua_money_allocation.Value_USD) )
4
  • How can I change the structure to make it add both? Aug 1, 2015 at 1:00
  • + instead of , ???
    – Rick James
    Aug 1, 2015 at 1:10
  • I am using a + sign. My error is that the operand can only return 1 column Aug 6, 2015 at 5:38
  • The comma says there are two columns. You have / ( this , that )
    – Rick James
    Aug 6, 2015 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.