[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 441
  • Last Modified:

group by a computed column didn't work in sybase. why?

In Sybase adaptive server 11, the following gave me 'invalid column name mnth'. How can I summarize sales by month?

select sum( subtotal ) as sales_summary,
  datediff ( mm,  'Jan 1 2000', order_date ) as mnth
from sales_order
where mnth > 0
group by mnth
0
xander031
Asked:
xander031
  • 2
1 Solution
 
AlexJ030200Commented:
Hi xander031,

Try replacing mnth by its definition in the conditions of the query:

select sum( subtotal ) as sales_summary,
datediff ( mm,  'Jan 1 2000', order_date ) as mnth
from sales_order
where datediff ( mm,  'Jan 1 2000', order_date ) > 0
group by datediff ( mm,  'Jan 1 2000', order_date )
0
 
xander031Author Commented:
I wonder whether the query optimizer will eliminate redundant calls of the function?
0
 
AlexJ030200Commented:
Sure it will, as long as they are written identically.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now