× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Jay Vaughn wrote:

But when I try to add... Max(Case When

Jay, several others have explained why you need GROUP BY, but one thing that helped me in the past is thinking about detail vs summary. Imagine trying to be the database engine trying to figure out how to put a total on a detail line...

GROUP BY is how we tell SQL that we want totals. Mixing total and detail can be done by performing two SELECTs and using UNION to put them together into a single result set.

select custnum, prodname, sales from cust_history UNION
select custnum, 'subtotal', sum(sales) from cust_history group by custnum
order by 1

--buck

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.