PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
with d as ( select DATE_FORMAT(rental_date, '%w') d, DATE_FORMAT(rental_date, '%W') day_of_week, COUNT(*) rentals_count from rental group by DATE_FORMAT(rental_date, '%w'), DATE_FORMAT(rental_date, '%W') ) select day_of_week, rentals_count , (rentals_count / sum(rentals_count) over ()) * 100 day_rental_rate from d order by d = 0, d;
Copy Clear
Copy Format Clear
<?php $query = "select title, rental_duration from film where film_id not in ( select film_id from rental join inventory using(inventory_id) where datediff(return_date, rental_date) > film.rental_duration ) order by title;;"; // get DB version using PDO $stmt = $pdo->prepare($query); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_NUM); $columns = []; for ($i = 0; $i < $stmt->columnCount(); $i++) { $col = $stmt->getColumnMeta($i); $columns[] = [ 'header'=>$col['name'], 'pdo_type'=>$col['pdo_type'] ]; } echo json_encode([[ 'headers' => $columns, 'data' => $rows ]], JSON_PRETTY_PRINT );
Show:  
Copy Clear