Create pager from db_query This my SQL query to fetch the details.

$query = "SELECT DISTINCT TITLE, PID, TYPE, SUM(DAYCOUNT) AS tot, ROUND(SUM(DAYCOUNT)/(
        SELECT SUM(DAYCOUNT) FROM REPORT_LIST_VIEW), 4) AS per
        FROM REPORT_LIST_VIEW
        WHERE DAYCOUNT &gt; '0'
        GROUP BY TITLE, PID, TYPE
        ORDER BY TITLE ASC";
        $res = db_query($query);


I am displaying out put like this

foreach ($res as $row) { 
$i++; ?&gt;
&lt;li&gt;
&lt;a href="/page-file-views-user?id=&lt;?php echo $row-&gt;pid ;?&gt;&amp;type=&lt;?php echo $row-&gt;type; ?&gt;" &gt;
&lt;ul class="inner-ul"&gt;
&lt;li class="name"&gt;&lt;?php echo ucfirst($row-&gt;title); ?&gt;&lt;/li&gt;
&lt;li class="percentage"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;?php echo $row-&gt;per * 100; ?&gt;%&lt;/li&gt;
&lt;li&gt;&lt;?php echo $row-&gt;tot; ?&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/a&gt;
&lt;/li&gt;
&lt;?php $sum+= $row-&gt;tot; } ?&gt;


How can I add a pagination (mini pager) at top &amp; bottom of the result?

&lt;?php 
function pager_array_splice($data, $limit = 9, $element = 0) {
  global $pager_page_array, $pager_total, $pager_total_items;
  $page = isset($_GET['page']) ? $_GET['page'] : '';
 // Convert comma-separated $page to an array, used by other functions.
  $pager_page_array = explode(',', $page); // outs puts empty array
  // We calculate the total of pages as ceil(items / limit).
  $pager_total_items[$element] = count($data); // output 1 
  $pager_total[$element] = ceil($pager_total_items[$element] / $limit); // output 1 
  $pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));  // no output
  return array_slice($data, $pager_page_array[$element] * $limit, $limit, TRUE);
}
?&gt;

And in my pagination div 

$output = '';
$customArr = pager_array_splice($data, 1);
$output .= theme('views_mini_pager', array('quantity' =&gt; 1));
print $output;

But no result is printing. Any error in my logic.
You want to take advantage of the PagerDefault class.

Write your query as a db_select query which I'll leave as an exercise for the reader because, frankly, I'm not sure if it's possible to create a db_select query with a subquery as part of an expression like that :).  Assuming you build up your select query in a variable called $query, you'd have code along these lines:

$query = db_select('REPORT_LIST_VIEW')-&gt;extend('PagerDefault');
...build up $query object here...
$res = $query-&gt;execute();

$pager = drupal_render(array('#theme' =&gt; 'pager'));


Then just output $pager wherever you want it.

Also, in general, I'd recommend placing this in a block rather than hard-coding it into your theme so that it's more reusable.