sql problem
am 10.01.2005 21:05:36 von Sikus
I have a one table with this columns:
date, article_name, quantity
I interesting how can I select from this table to get
article_name, sum(quantity) for all dates in table
and
article_name, sum(quantity) for one date in one statment.
something like this, but don't know whats next:
select article_name, date, sum(quantity) as mysum from mytable group by
date, article_name having mysum <> 0 order by article_name;
Sikus
Re: sql problem
am 12.01.2005 13:40:37 von Erwin Moller
Sikus wrote:
> I have a one table with this columns:
>
> date, article_name, quantity
>
> I interesting how can I select from this table to get
>
> article_name, sum(quantity) for all dates in table
> and
> article_name, sum(quantity) for one date in one statment.
>
> something like this, but don't know whats next:
>
> select article_name, date, sum(quantity) as mysum from mytable group by
> date, article_name having mysum <> 0 order by article_name;
>
> Sikus
Hi,
What excactly do you expect to be in the result?
The first question you answered yourself: just use GROUP BY
But how do you expect to get the answer to your second question in the same
resultset?
You first question returns many dates/article_names.
You second questions just returns article_names for a certain date.
Maybe I misunderstood your question, but I think you make a logical error.
I think you DON'T want what you ask for. :-)
Why not make 2 queries?
I cannot think of any valid reason...
PS: For a primer on SQL try:
http://www.w3schools.com/sql/default.asp
Good luck!
Regards,
Erwin Moller