SQL学习内容
1.根据某字段计数时不记重复数据
SELECT
( SELECT COUNT( t1.IDCARD ) FROM TABLE1 t1 ) buildPerNum,
( SELECT
COUNT( t3.ID) FROM
( SELECT DISTINCT t2.ID FROM TABLE2 t2 ) t3 ) groupPerNum
FROM
dual
distinct根据t2表的字段将t2表去重,然后将去重后的表命名t3,再根据t3表的字段count计算数量
2.WHERE下加判定条件
SELECT
t1.GPS GPS
FROM
TABLE1 t1
WHERE
t1.GPS IS NOT NULL
<if test="riskLevel != null and riskLevel != ''">
AND T1.RISK_LEVEL = #{riskLevel}
</if>
</select>