根据CODE去重
SELECT
*
FROM
( SELECT count( camera_code ) AS count, camera_code FROM n_camera_basic GROUP BY camera_code ) t
WHERE
t.count >1
DELETE FROM n_camera_basic
WHERE
camera_id NOT IN (SELECT
dt.minno
FROM
(SELECT
MIN(camera_id) AS minno
FROM
n_camera_basic
GROUP BY camera_code) dt);
批量插入 <insert id="insertSubScribeBatchByViDeptSubscribe"parameterType="com.netintech.video.deptsubscribe.domain.ViDeptSubscribe">INSERT INTO vi_subscribe_camera (camera_code,camera_name,catalog_type,)<foreach item="item" collection="list" separator=" UNION ">selectcamera_code,camera_name,(SELECT UNIX_TIMESTAMP()) update_time_longFROMn_camera_basicWHERE del_flag = '0'AND orgs_id=#{item.deptId}</foreach> </insert>
批量更新
<update id="updateViCameraForeachBatch" parameterType="com.netintech.video.newsubscribe.domain.ViSubscribeCamera">update vi_subscribe_camera<set><trim prefix="subscribe_status = case" suffix="end,"><foreach collection="list" item="item">when id=#{item.id} then #{item.subscribeStatus}</foreach></trim><trim prefix="update_time = case" suffix="end,"><foreach collection="list" item="item">when id=#{item.id} then #{item.updateTime}</foreach></trim><trim prefix="update_time_long = case" suffix="end,"><foreach collection="list" item="item">when id=#{item.id} then (SELECT UNIX_TIMESTAMP())</foreach></trim><trim prefix="del_flag = case" suffix="end,"><foreach collection="list" item="item">when id=#{item.id} then #{item.delFlag}</foreach></trim></set><where>id in<foreach collection="list" separator="," item="item" open="(" close=")">#{item.id}</foreach></where> </update>
分组,查询连续五个月没有出现V这个值就加1
SELECTz.YEARDATA yearData,sum(z.flag) ljtz FROM(SELECTA.YEARDATA,CASEWHENSUM(CASE WHEN DYFL = '劣V' THEN 1 ELSE 0 END) OVER (ORDER BYYEAR(TO_DATE(YEARDATA, 'YYYY-MM')),MONTH(TO_DATE(YEARDATA, 'YYYY-MM')) ROWS BETWEEN 5 PRECEDING AND 1 PRECEDING) > 0THEN 1ELSE 0END AS flagFROMYW_QVLHD aWHEREA.xqmc LIKE concat('%', '市长环保目标责任书考核', '%')ORDER BYA.YEARDATA )Z GROUP BYz.YEARDATA ORDER BYz.YEARDATA