CREATE TABLE testtable1(id INTEGER AUTO_INCREMENT PRIMARY KEY,department VARCHAR(12));
INSERT INTO testtable1 VALUES(1,"设计");
INSERT INTO testtable1 VALUES(2,"市场");
INSERT INTO testtable1 VALUES(3,"售后");
SELECT * FROM testtable1
CREATE TABLE testtable2(
id INTEGER AUTO_INCREMENT PRIMARY KEY ,detID INT, sname VARCHAR(20)
)
INSERT INTO testtable2 VALUES(1,1,"张三")
INSERT INTO testtable2 VALUES(2,1,'李四')
INSERT INTO testtable2 VALUES(3,2,'王五')
INSERT INTO testtable2 VALUES(4,3,'彭六')
INSERT INTO testtable2 VALUES(5,4,'陈七')
ISNULL
SELECT testtable2.*,IFNULL(department ,"黑人")FROM testtable1
RIGHT JOIN testtable2 ON testtable2.detID = testtable1.id
用iffull函数可以得到想要的结果