The present application relates to a pyrazolopyrimidine compound of Formula (I) and a pharmaceutically acceptable salt thereof. Such compounds can be used to inhibit the activity of a lipid kinase PI3K, and can also be used to treat diseases mediated by PI3K, such as cancers, inflammatory diseases, and autoimmune diseases. The present application also relates to a pharmaceutical composition containing such compounds, a method for preparing such compounds, and use of such compounds or pharmaceutical compositions in the preparation of a drug for treating cancers, inflammatory diseases, and autoimmune diseases mediated by PI3K.