Hi DBA's -
Kindly help me figure out the following
My data looks like this -
Month Product Brand Revenue
-- --- --- ---
Jan A x 10
Jan A y 20
Jan B z 30
A report from the above data would be
Revenue for Jan = 60 and Product count = 2.
So I figure, I would need
Month Product Brand Revenue Flag
-- --- --- --- --
Jan A x 10 1
Jan A y 20 0 (since A is counted)
Jan B z 30 1
I want to count only the first occurence of the product in the Flag column.
Is there a way to do this.
- Vivekselect Month,
sum(Revenue),
Count(distinct Product)
from YourTable
group by Month|||select [month],
productcount=count(distinct product),
totalrevenue=sum(revenue)
from your_table
group by [month]|||hey, I just didn't click on Submit, because there other things in life, like phone calls!!!!|||Phone calls?
That's OLD TECHNOLOGY...
Your code was more complete, anyway. I confess I was being a little lazy...|||But did you notice the snippets are almost identical? This is earie...|||You are just saying that to be nice. Yours was much more colorful than mine as well. I simply lack your aesthetic sense of code.
Mine was pathetic. A shoddy hack of garbled syntax totally lacking in character or depth. In my haste to post, I neglected that which makes code enjoyable and pleasing to the senses.
I am truly ashamed.
Wait a minute... "Groupby"?
Hey! "Group by" is two words, not one! That won't even compile, much less execute!
Hmmph! Well. I guess I feel better now. :)|||Now who's a real hoot? :Dsql
No comments:
Post a Comment