Example module to change the sort order of comments in Drupal 8 using function hook_query_TAG_alter. It is possible to configure sort order (newer or older first) per comment field, using the "comment field configuration" in "manage fields and settings" for your content type.
Corresponding issue for Drupal 7:
=> https://www.drupal.org/node/1095656
Drupal 8.2.x database.api.php / Perform alterations to a structured query for a given tag: