Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thearyanahmed/6f1e6154b8d0e259f142e256ed3aeb88 to your computer and use it in GitHub Desktop.
Save thearyanahmed/6f1e6154b8d0e259f142e256ed3aeb88 to your computer and use it in GitHub Desktop.
Do you seen any security issue here?
$query = "SELECT
country.country_name_eng,
SUM(CASE WHEN call.id IS NOT NULL THEN 1 ELSE 0 END) AS calls,
AVG(ISNULL(DATEDIFF(SECOND, call.start_time, call.end_time),0)) AS avg_difference
FROM country
-- we've used left join to include also countries without any call
LEFT JOIN city ON city.country_id = country.id
LEFT JOIN customer ON city.id = customer.city_id
LEFT JOIN call ON call.customer_id = customer.id
GROUP BY
country.id,
country.country_name_eng
-- filter out only countries having an average call duration > average call duration of all calls
HAVING AVG(ISNULL(DATEDIFF(SECOND, call.start_time, call.end_time),0)) > (SELECT AVG(DATEDIFF(SECOND, call.start_time, call.end_time)) FROM call)
WHERE id > = $_POST[ 'id' ]
ORDER BY calls DESC, country.id ASC;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment