select *
from t
order by value desc
fetch first 1 rows with ties;
select
t.*,
count(*) over (partition by number_id)
from t order by id;
<?php
$f = fopen("your.file", "r");
if ($f) {
$today = strtotime(date("Y-m-d"));
while (($line = fgets($f)) !== false) {
preg_match('/\d+\s(\d{2}\.\d{2}\.\d{4})/', $line, $m);
if ($m && strtotime($m[1]) < $today) {
echo $line . PHP_EOL;
}
}
fclose($f);
}
<?php
require "includes/config.php";
$articlesx = mysqli_query($connection, "SELECT * FROM `matem` ORDER BY `views` DESC LIMIT 8");
while($artx = mysqli_fetch_assoc($articlesx)) {
echo '<li><a href="#">'.$artx.'</a></li>';
}
echo '<li><a href="#">'.$artx['тут какой-то ключ'].'</a></li>';
SELECT * FROM `table`
WHERE 1 IN (`с1`,`с2`,`с3`);
select
date(`datetime`),
sum(case when `action_type` = 'value_add' then `value` else -`value` end) `total`
from t
group by date(`datetime`)
select distinct year(d) from t;
<?php
$num = 12345678900000000;
$pow = floor(log10($num));
echo $num / pow(10, $pow) . ' * 10^'.$pow;
with numbered_rows as (
select
*,
row_number() over(partition by user_id order by col2) as rn -- нумеруем строки каждого юзера в порятке возрастания col2
from t
) select * from numbered_rows where rn < 4 -- выбираем первые 3 строки на юзера
order by user_id, rn;
$sth = $pdo->prepare(
"SELECT 1
FROM `ok`
WHERE `val` = ?
LIMIT 1"
);
$sth->execute([$val]);
if ($sth->rowCount() > 0) {
printf("Value %s found in table `ok` column `val`", $val);
} else {
printf("Value %s not found in table `ok` column `val`", $val);
}
<?php
$arr = [0,1,2,3,4,5,6,7,8,9];
$cnt = count($arr);
$shuffled = [];
while ($cnt>0) {
$shuffled = array_merge($shuffled, array_splice($arr, rand(0, $cnt), 1));
$cnt--;
}
print_r($shuffled);