I can't say $334k is typical but I can say I have more than that in household income by quite a bit. Just as a reference and a joke if you are in Palo Alto the qualifying line of affordable housing program for a family of 4 is $200k in total family income.
Most of the people with 2M home purchase either roll in their gain from previous home (they are not first time buyer and had some home appreciation from a prior cheaper smaller home or condo, for example), or they sold other investment to get a down payment for that 2M home. Yes, Bay Area is not an average income US metro. It is near the top of US if not already the top. You can't use average US household income to value NYC real estate price for the same reason. There are a lot of choices for people who can't afford the perfect home: you can get a condo or townhouse in good school district, or commute from far away, or just don't go to a good school district and send the kids to a private school (private schools here aren't automatically better than public schools mind you), or just rent for a few years during the school district need.
Another couple of things are: we have prop 13 so it limits property tax increase over time regardless of home appreciation. So this is why many old people refuse to sell and leave to somewhere just slightly cheaper, because they would lose that property tax discount. There are also cheaper places to live if you don't mind commuting, like Livermore and Gilroy, but you are paying for it in commute stress.
$400k for down pay is really not a lot if you work for a company that has a lot of stock, and people switch jobs a lot for these up side. Managing your own investment in the stock market is also as important as your work performance and spending habits.