SELECT `day`, `priority`, `count`
FROM (
(SELECT 'today' AS `day`, `priority`, COUNT(*) AS `count`
FROM `table`
WHERE `time` >= CURDATE() AND `time` < CURDATE() + INTERVAL 1 DAY
GROUP BY `priority`)
UNION ALL (SELECT 'yesterday', `priority`, COUNT(*)
FROM `table`
WHERE `time` >= CURDATE() + INTERVAL 1 DAY AND `time` < CURDATE() + INTERVAL 2 DAY
GROUP BY `priority`)
) AS `t`
$result = [];
foreach ($arr as [$name, $price]) {
$result[$name] = [
'name' => $name,
'totalPrice' => ($result[$name]['totalPrice'] ?? 0) + $price,
'count' => ($result[$name]['count'] ?? 0) + 1
];
}
$result = array_values($result);
/*
array(2) {
[0] => array(3) {
["name"] => string(8) "iphone 0"
["totalPrice"] => int(156000)
["count"] => int(4)
}
[1] => array(3) {
["name"] => string(7) "macbook"
["totalPrice"] => int(300000)
["count"] => int(1)
}
}
*/
SELECT `s`.`time`, `o`.`time` IS NULL AS `free`
FROM `timeslots` AS `s`
LEFT JOIN `orders` AS `o`
ON `o`.`date` = :date AND `o`.`time` = `s`.`time`
SELECT `time`
FROM `timeslots`
WHERE `time` NOT IN (
SELECT `time`
FROM `orders`
WHERE `date` = :date
)
class Baz
{
public function bar() {
$this->foo();
}
public function foo() {
$backtrace = debug_backtrace();
$stack = array_map(
function($el) {
return "{$el['class']}{$el['type']}{$el['function']}";
},
$backtrace
);
var_dump($stack);
}
}
$t = new Baz;
$t->bar();
/* array(2) {
[0] => string(8) "Baz->foo"
[1] => string(8) "Baz->bar"
} */