Teradata 3504/3627 Issue
I keep having the same issue revolving a particula开发者_开发百科r query which has the following column:
CAST((COALESCE(price, 0.000000)) AS DECIMAL(18,6)) * quantity amount (TITLE 'Amount')
If I don't mention it in the group by it spews error 3504, if I do it spews back error 3627.
Any idea on how to properly structure this part of the query?
edit: if you need more info, please ask away :)
I believe you are experiencing multiple problems here (it's hard to say without more code).
The 3504 occurs when this column is not part of the GROUP BY clause because all columns that aren't part of the GROUP BY must be "aggregate" functions (eg. SUM, MAX, MIN, AVG, etc). When you do include it in the GROUP BY, this column is now fine.
However, my guess is that you also have a COUNT(DISTINCT(x)) in you SELECTion list. You can't use the DISTINCT function in the SELECT, ORDER BY, or HAVING clause of a query when also using a GROUP BY. I suspect if you remove the DISTINCT, leaving you with COUNT(*), this will work.
As an aside, I'm not sure you want to be grouping by the column you mention here. It's unusual to group on a financial amount. It would be more common for this column to be aggregated with a SUM function for instance. Or otherwise you may want to reconsider why you're using a GROUP BY (as grouping by the "amount" will give you odd results, essentially giving you one row for each row returned, except where the GROUP BY columns and the "amount" are the same, where it will collapse it down to a single row, meaning you will get inconsistent results).
Hope this helps.
精彩评论