Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- region.`name`,
- u2.username AS chief,
- user.username AS supervisor,
- user.id AS supervisor_id,
- Sum(s1.count_photo) AS sum,
- (
- SELECT
- COUNT(*)
- FROM
- (
- SELECT
- Count(photo.id) as c
- FROM
- photo
- INNER JOIN
- report
- ON photo.report_id = report.id
- INNER JOIN
- availability
- ON report.availability_id = availability.id
- INNER JOIN
- place as place2
- ON availability.place_id = place2.id
- WHERE
- place2.supervisor = place.supervisor AND
- availability.removed IS NULL
- GROUP BY
- report.availability_id
- HAVING
- c = 1
- )
- x
- ) AS Target
- FROM
- furniture s1
- INNER JOIN
- availability
- ON availability.furniture_id = s1.id
- INNER JOIN
- place
- ON availability.place_id = place.id
- INNER JOIN
- user
- ON place.supervisor = user.id
- INNER JOIN
- region
- ON place.region_id = region.id
- INNER JOIN
- sector
- ON place.sector_id = sector.id
- INNER JOIN
- user AS u2
- ON sector.chief = u2.id
- WHERE
- availability.removed IS NULL
- AND s1.deleted_at IS NULL
- GROUP BY
- place.supervisor
Advertisement
Add Comment
Please, Sign In to add comment