sql中的null,'',isnull()的区分


一、问题:因某种原因,导致数据库中sql的某些字段存的是‘’,null,在做数据处理遇到了难题。分组查询的时候,导致会出现‘’,和null  两组数据。


sql :SELECT QZJYYX AS nameas , COUNT(1) AS countas FROM PERSON_INFO P LEFT JOIN FRM_SYSUSER U ON U.YHDH = P.YHDH WHERE P.YHDH IN (SELECT T.YHDH FROM FRM_SYSUSER T WHERE GLBM LIKE '2208%')  GROUP BY QZJYYX;



处理方式:


SELECT CASE WHEN (IfNULL(QZJYYX,''))='' OR QZJYYX = 'null'  THEN '' ELSE QZJYYX END AS nameas ,COUNT(1) AS countas FROM PERSON_INFO  WHERE EXISTS (SELECT 1 FROM FRM_SYSUSER  WHERE YHDH = PERSON_INFO.YHDH AND GLBM LIKE'2208%') GROUP BY  CASE WHEN IfNULL(QZJYYX,'')='' OR QZJYYX = 'null'  THEN '' ELSE QZJYYX END;




你可能感兴趣的:(sql,数据,数据库)