insert into device(id, scenic_id, name, no) values (#{id}, #{scenicId}, #{name}, #{no})
update device set scenic_id = #{scenicId}, name = #{name}, no = #{no} where id = #{id}
update device
set status = (CASE
status
WHEN 1 THEN
0
WHEN 0 THEN
1
ELSE null
END)
where id = #{id}
delete from device where id = #{id}
select d.id, scenic_id, d.name, no, d.status, create_at, d.update_at, s.name scenic_name
from device d
left join scenic s on d.scenic_id = s.id
and d.`name` like concat('%', #{name}, '%')
and `no` like concat('%', #{no}, '%')
and d.`status` = #{status}
and scenic_id = #{scenicId}
and d.create_at >= #{startTime}
and d.create_at <= #{endTime}
select d.id, scenic_id, d.name, no, d.status, create_at, d.update_at, s.name scenic_name
from device d
left join scenic s on d.scenic_id = s.id
where d.id = #{id}
select d.id, d.name, no, d.status, create_at, d.update_at
from device d
where d.scenic_id = #{scenicId}
select ifnull(a.totalDeviceCount,0) as totalDeviceCount,ifnull(b.shotDeviceCount,0) as shotDeviceCount
from (
select count(1) totalDeviceCount,scenic_id
from device
where scenic_id = #{scenicId} and status = 1
)a
left join (
select count(1) shotDeviceCount,scenic_id
from source
where scenic_id = #{scenicId}
group by device_id
)b on a.scenic_id = b.scenic_id