WITH Ranked AS (
SELECT
OP.*,
DENSE_RANK() OVER (ORDER BY O.ID DESC) R
FROM Orders O
JOIN OrdersProducts OP ON O.Id = OP.OrderID
) SELECT * FROM Ranked
WHERE R <= 3;
WITH Last3Orders AS (
SELECT TOP(3) Id FROM Orders O
ORDER BY Id DESC
) SELECT * FROM Last3Orders
JOIN OrdersProducts ON Last3Orders.Id = OrdersProducts.OrderID
ORDER BY OrderID DESC;
CREATE TABLE users (
id int primary key auto_increment,
name varchar(64)
);
CREATE TABLE favorites (
user_id int references users(id),
bookmark varchar(255),
primary key (user_id, bookmark)
);
ALTER TABLE users ALTER COLUMN user_id ADD GENERATED BY DEFAULT AS IDENTITY;
select *
from tbl
order by row_number() over(partition by user_id order by views desc), views desc;
<?php
if (10 <= date("G") && date("G") <= 20) {
echo "сейчас на сервере от 10 до 20 часов.";
}
<?php
$commands = [
'hi' => fn($name) => 'hi, ' . $name,
'hello' => fn($name) => 'hello , ' . $name,
'etc' =>fn($name) => 'etc...',
];
echo $commands['hi']('John');
<?php
$arr = [1, 3, 4, 6, 4, 2, 1, 1];
$res1 = array_count_values($arr);
//var_export($res1);
$res2 = array_filter($res1, fn($el)=>($el>1));
var_export(array_keys($res2));
json_encode(
[ 'Цена' => intval($_GET['price'] * 100 )/100 ],
JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
);
<?php
$date = date('Y-m-01');
$next_month = date('Y-m-d', strtotime('+1 month', strtotime($date)));
function nextWorkDay($date) {
$day_of_week = date('N', strtotime($date));
if ($day_of_week>5) {
//echo "Weekend: " . $date;
$shift = 8-$day_of_week;
return date('Y-m-d', strtotime("+{$shift} day", strtotime($date)));
} else {
echo "Work day ($day_of_week):" . $date . PHP_EOL;
return date('Y-m-d', strtotime('+3 day', strtotime($date)));
}
}
while ($date < $next_month) {
$date = nextWorkDay($date);
}