How to create a controller that runs query? I have a query: 

$sub_query = \Drupal::database()-&gt;select('test_file_discovery', 'f')
  -&gt;fields('f', ['nid'])
  -&gt;condition('extension', 'pdf');
$or = $sub_query-&gt;orConditionGroup()
  -&gt;condition('path', \Drupal::database()-&gt;escapeLike('_TT'), 'LIKE')
  -&gt;condition('path', \Drupal::database()-&gt;escapeLike('_OT'), 'LIKE')
  -&gt;condition('path', \Drupal::database()-&gt;escapeLike('_AT'), 'LIKE');
$sub_query-&gt;condition($or);

$query = \Drupal::database()-&gt;select('node_field_data', 'n')
  -&gt;fields('n', ['nid'])
  -&gt;condition('type', 'article')
  -&gt;condition('nid', $sub_query, 'IN');
$query-&gt;range(0, 10);


But I don't know how to create a controller / page where I can display this query's results in a table, "Name" and "Actions" as labels / headers.

Anyone can give me assistance?!
@asrob,
Please refer the basic docs provided by Clive to create a controller in drupal 8 with route to access the same or 
this link to create a custom module in drupal
and follow this sample code below to display your data in table format along with a pager:

  &lt;?php

  /**
   * @file
   * Contains \Drupal\custom_module_name\Controller\DetailsController
   */

  namespace Drupal\custom_module_name\Controller;

  use Drupal\Core\Controller\ControllerBase;

  /**
   * Description of DetailsController
   *
   * @author aaditya.walawalkar
   */
  class DetailsController extends ControllerBase {

    const RECORDS_PER_PAGE = 10;

    /**
     * {@inheritdoc}
     */
    public function getRecords() {

      $records = $query_result_from_query;

      // total records
      $totalRecords = $total_records_count_from_query;
      $recordsPerPage = self::RECORDS_PER_PAGE;
      // initialize pager
      $page = pager_default_initialize($totalRecords, $recordsPerPage);

      $offset = $recordsPerPage * $page;

      $data = array();
      foreach ($records as $delta =&gt; $details) {
        $data[] = array('data' =&gt; array(
          $details['name'],
          $details['remarks'],
        ));
      }

      $recordsToDisplay = [];
      $recordsToDisplay[] = [
        '#theme' =&gt; 'table',
        '#header' =&gt; array($this-&gt;t('Name'), $this-&gt;t('Remarks')),
        '#rows' =&gt; $data,
        '#empty' =&gt; $this-&gt;t('No Records(s) Found.'),
      ];

      // Finally, add the pager to the render array, and return.
      $recordsToDisplay[] = ['#type' =&gt; 'pager'];
      return $recordsToDisplay;

    }
  }