A quantum statistical theory of the superconductivity in MgB2 is developed regarding it as a member of the graphite intercalation compound. The superconducting temperature Tc for MgB2, C8K ≡ KC8, CaC6, are 39 K, 0.6 K, 11.5 K, respectively. The differences arise from the lattice structures. In the plane perpendicular to the c-axis, B's form a honeycomb lattice with the nearest neighbour distance a 0 while Mg's form a base-hexagonal lattice with the nearest neighbour distance a 0 3 above and below the B-plane distanced by c 0. The more compact B-plane becomes superconducting due to the electron-phonon attraction. Starting with the generalized Bardeen-Cooper-Schrieffer (BCS) Hamiltonian and solving the generalized Cooper equation, we obtain a linear dispersion relation cp = ε for moving Cooper pairs. The superconducting temperature Tc identified as the Bose-Einstein condensation temperature of the Cooper pairs in two dimensions is given by T cn k 1 2 1 c 0 B 1.954 − = , where n 0 is the Cooper pair density, k B the Boltzmann constant. The lattices of KC8 and CaC6 are clearly specified.