MySQL-- Outreach statement Exercise

- createholy,. 1, 50 
the CREATE DATABASE WL; 
the DROP TABLE MSP; 
the DROP TABLE Party; 

the CREATE TABLE Party ( 
  partyCode VARCHAR (10) the NOT NULL, - number 
  partyName VARCHAR (50), - the name of 
  leader VARCHAR (50), - - leaders 
  PRIMARY KEY (partyCode) 
) the DEFAULT CHARSET = utf8; 

the CREATE TABLE msp ( 
  mspName VARCHAR (50) the NOT NULL - No 
  party VARCHAR (10), - political 
  constituency VARCHAR (50), - supporters 
  PRIMARY KEY ( mspName), 
  a FOREIGN KEY (party) the REFERENCES party (partyCode), 
) the DEFAULT CHARSET = utf8; 

the SELECT * the FROM party; 
the SELECT * the FROM msp; 

- Members find no political party 
SELECT * FROM msp WHERE party iS NULL
 
- list All political parties and leaders
PartyName the SELECT, the FROM Party Leader 

- lists all the political parties have leaders of 
the SELECT * the FROM Party Leader the WHERE IS the NOT NULL 

- Members of the list has at least one political party 
. SELECT p * FROM party p, msp m WHERE p.partyCode = the GROUP BY p.partyCode m.party 

- lists the names of all members of their own party and 
the SELECT m.mspName, p.partyName the FROM LEFT JOIN party the p-msp m = ON p.partyCode m.party 

- lists all political parties and every a number of members of political parties 
SELECT p.partyName, COUNT (m.mspName) FROM party p JOIN msp m ON p.partyCode = m.party GROUP BY p.partyCode

  

Guess you like

Origin www.cnblogs.com/xieshilin/p/11780219.html