|
We Are The Change We Seek "i got this" - Kenny Wyland This isn't where I thought I was going to be when I looked forward into my life, but here I am.... Yes We Can |
||
| :: HOME :: GET EMAIL UPDATES :: My Amazon Wish List :: Atlanta Atheist Campaign Donations :: My ThinkGeek Wish List :: My Flickr Photostream :: Informed Comment :: Google Blog! :: FromJournalScapeHQ :: Ken :: Snow Jam :: EMAIL :: | ||
|
Read/Post Comments (5) ![]() |
2009-12-20 9:33 AM SQL Nerds: Question about selecting based on column aliases Consider a table with a Title column and a Units column where the Units is the number of sales of a particular Title. There are more columns like a date and such. I would like to select the total number of sales for each Title: select
distinct(Title),
sum(Units)
from my_table
group by Title
order by Title;
That's easy enough. The part that is giving me trouble is that I would like to combine that data into a single column (or third column as necessary). I would essentially like to produce a "Title sum(Units)" similar to the third column in this query: select
distinct(Title) as myTitle,
sum(Units) as totalSales,
concat(myTitle, ' ', totalSales) as combinedLabel
from my_table
group by Title
order by Title;
However, you can't reference column aliases when doing these kinds of things, so I'm at a loss. Any suggestions? Read/Post Comments (5) Previous Entry :: Next Entry Back to Top |
|
|
|
© 2001-2010 JournalScape.com. All rights reserved. All content rights reserved by the author. custsupport@journalscape.com |