SQL Select Help

Hello EE,
i have a select result like this :

153010      11      LDS       14      803500046178      153      1      A001
153010      11      LDS       14      803500046178      153      1      A010
153010      11      LDS       14      803500046178      153      4      J03
153010      11      LDS       16      803500046185      153      3      A010
153010      11      LDS       16      803500046185      153      1      J03
153010      21      LDS       14      803500046277      153      3      A002
153010      21      LDS       14      803500046277      153      1      A010

you see that by UPC, i have multiple values (see last column)
I would like to add a column where i would see the total by UPC, a result like this:

153010      11      LDS       14      803500046178      153      1      A001    3
153010      11      LDS       14      803500046178      153      1      A010    3
153010      11      LDS       14      803500046178      153      4      J03       3
153010      11      LDS       16      803500046185      153      3      A010    2
153010      11      LDS       16      803500046185      153      1      J03        2
153010      21      LDS       14      803500046277      153      3      A002     2
153010      21      LDS       14      803500046277      153      1      A010     2

so it would be the count by UPC

how can I do this to the actual results?
LVL 1
PhilippeRenaudAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>you see that by UPC
Please add the column names to your data mockup, as I don't see a 'UPC' anywhere, and it's not clear what you wish to count.
0
PhilippeRenaudAuthor Commented:
see picture for better explanations.


i want a column where it would say the count of upc in my table.
in my example, you see 4 rows with that upc:   803500105288

so in the new column, for each of this upc, i would see "4"

let me know if it makes more sense.
0
PhilippeRenaudAuthor Commented:
sorry here is the picturesql.png
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
For starters, give this a whirl.  Change your_table to your table name, rename any obvious stuff, and this is total air code

SELECT Styple1, StyleColor, Desc, Size, yt.UPC_NO, Season, BIN_NO, yt_sum.qty_sum
FROM your_table yt
   JOIN (
      SELECT UPC_NO, SUM(Qty) as qty_sum
      FROM your_table
      GROUP BY UPC_NO) yt_sum ON yt.UPC_NO = yt_sum.UPC_NO

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
btw, please also use the image and code buttons and not the file attach buttons, as that keeps everything in one view and saves experts a lot of time clicking back and forth, which leads to faster answers. ask-question-buttons.jpg
1
PhilippeRenaudAuthor Commented:
i made it happen with your code, i just changed the sum(Qty) to count(UPC_No)

thanks
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.