tags:

views:

86

answers:

1

I am trying to run the query shown below to include the results in a report and am getting a 'Operand should contain 1 column' error #1241. I have not been able to figure out the cause of this. If I run this part by itself I do not get any errors: '(pct_return_1 * .25) + (pct_return_2 * .25) + (pct_return_3 * .15) + (pct_return_4 * .15) + (pct_return_5 * .2)'

Here is the code:

DROP TABLE IF EXISTS temp_5; CREATE TABLE temp_5 ( date_value date default NULL, pct_return_portfolio double default NULL, pct_return_benchmark double default NULL);

INSERT INTO temp_5 (date_value, pct_return_portfolio, pct_return_benchmark) SELECT (date_value, (pct_return_1 * .25) + (pct_return_2 * .25) + (pct_return_3 * .15) + (pct_return_4 * .15) + (pct_return_5 * .2) FROM Temp_4), pct_return_6) FROM temp_4;

Thanks, Eric

A: 

Try removing the first occurrence of FROM Temp_4 (the one just after the second value in the subquery).

Edit: Also double check parenthesis groupings, as in this example:

INSERT INTO table2 (field1, field2, field3, field4) (SELECT 'value1 from user input', field1, field2, field3 from table1)

Which is given on this page regarding insert subqueries: http://dev.mysql.com/doc/refman/5.1/en/subqueries.html

JYelton
I tried your suggestion and below is my actual query. The query did not run successfully. I received the same error message. INSERT INTO temp_5 (date_value, pct_return_portfolio, pct_return_benchmark) SELECT (date_value, ( (pct_return_1 * .25) + (pct_return_2 * .25) + (pct_return_3 * .15) + (pct_return_4 * .15) + (pct_return_5 * .2) ), pct_return_6) FROM temp_4;
In the example I found, the select statement or subquery is completely enclosed in parenthesis. So on your statement, place an open parenthesis before "SELECT" and another after "FROM temp_4" hopefully that works for you. Subqueries are picky!
JYelton