We have now seen the second-quarter results from the largest banks in the United States, and it's tough to make the case that Goldman Sachs (GS 1.59%) isn't an earnings season winner compared to its peers. Not only did it handily beat expectations on both the top and bottom lines, but the stock trades at an attractive valuation, and the financial institution is growing in certain ways that long-term investors should pay close attention to.

While it could certainly face some near-term headwinds if a recession hits, Goldman Sachs looks like a compelling buying opportunity for investors who measure their returns in multiyear periods. Here's a rundown of how its business is doing, and why it looks like an especially attractive investment right now.

Second-quarter results show the bank's resilience

To be sure, there were some negative features in Goldman's second-quarter numbers. Most significantly, earnings fell by 48% year over year, mainly due to a worldwide slowdown in investment banking. Mergers and acquisitions activity, as well as equity and debt underwriting, has dried up due to the uncertain economic climate, and the numbers show just how bad it is. Goldman's investment banking fee revenue dropped by 41% compared to the prior-year period.

However, it's important to realize that Goldman Sachs is built to make money no matter what the macro conditions are. While investment banking and wealth management generally fare poorly in turbulent markets, its massive trading operation tends to benefit from higher volatility. In fact, fixed income trading revenue increased by a staggering 55% year over year. In all, trading revenue came in at about $6.5 billion -- 32% higher than a year ago and more than half of the bank's total revenue.

The surge in trading revenue allowed Goldman Sachs to beat expectations on both the top and bottom lines, showing just how resilient it can be in rough markets.

Consumer banking remains an under-the-radar growth driver

One of the most overlooked parts of Goldman Sachs, and one of the most compelling reasons to own the stock, is its consumer banking business.

The company is known as an investment banking giant, but it has been quietly building its consumer banking operations for several years now. It started with the Marcus savings and loan platform, and has since added credit card lending and a robo-advisory platform.

In the second quarter, its consumer banking revenue grew by 67% year over year, fueled by strong credit card balance growth -- it's the bank behind the Apple (NASDAQ: AAPL) and General Motors (NYSE: GM) credit cards -- as well as higher deposit balances, which give the bank a low-cost source of funding.

This could be just the beginning. Goldman Sachs' management has specifically mentioned things like offering checking accounts and more types of loans as possible future growth drivers. Given that consumer banking provides just over 5% of the institution's revenue today, there's room for years of rapid growth as it evolves into a more well-rounded bank.

The price is right

Goldman Sachs stock is trading about 24% below its all-time high, which isn't quite as poorly as some of its peers have fared during the recent downturn. But at just 7.2 times trailing 12-month earnings and just over its book value, the bank looks like a compelling value. And even with its earnings expected to contract due to the current climate, Goldman still trades for less than 9.5 times forward earnings. The dividend yields an attractive 3.1% at the current share price, and the company has aggressively been buying back its shares. In short, Goldman Sachs looks like an extremely cheap bank stock considering its resilience and growth potential.