select user_id
from tbl
where entity_id in (24, 25)
group by user_id
having count(distinct entity_id) = 2;
create table user_balance (
user_id int,
balance decimal(9, 2) check (balance >=0)
);
create table user_balance_unsigned (
user_id int,
balance decimal(9, 2) unsigned
);
<?php
function myRound($n) {
$d = (int)log10($n) - 1;
return ceil($n/10**$d) * 10**$d;
}
<?php
$query = "SELECT COUNT(*) cnt FROM sakila.actor;";
// get DB version using PDO
$stmt = $pdo->prepare($query);
$stmt->execute();
$count = $stmt->fetchColumn();
printf("Count rows in table actor is: %d", $count);
$url1arr = array_column($arr1, 'url');
foreach ($arr2 as $arr2s) {
$key = null;
$key = array_search( $arr2s['url'] , $url1arr );
//Если не нашел будет действие
if ( $key == false) {
var_dump ($arr2s);
}
}
$url1arr = array_column($arr1, 'url', 'url');
foreach ($arr2 as $arr2s) {
//Если не нашел будет действие
if (!isset($url1arr[$arr2s['url']])) {
var_dump ($arr2s);
}
}
WITH RECURSIVE tmp AS (
SELECT REPORT_DATE rdate FROM ODK_INT_rep_p2 WHERE ODK_INT_rep_p2id IN (
SELECT nvl((SELECT ODK_INT_rep_p2id FROM ODK_INT_rep_p2 WHERE TYPE = 2 AND report_date = (SELECT report_date FROM ODK_INT_rep_p2 WHERE ODK_INT_rep_p2id = (SELECT max(ODK_REP_P2ID) FROM odk_svodka_skc2))),
(SELECT ODK_INT_rep_p2id FROM ODK_INT_rep_p2 WHERE TYPE = 2 AND report_date = (SELECT report_date
FROM ODK_INT_rep_p2 WHERE ODK_INT_rep_p2id = (SELECT max(ODK_INT_rep_p2id) AS ODK_INT_rep_p2id
FROM ODK_INT_rep_p2 WHERE TYPE = 1 AND trunc(report_date)= trunc(current_timestamp))))) AS id1
FROM
dual)),
WITH cte_months (day) AS (
...
)
select
date_trunc('month', data),
login,
value,
sum (value) over (
partition by login, date_trunc('month', data)
order by data rows between unbounded preceding and current row
) as lag_value
from
t1;
create or replace function trunc (x timestamp)
returns date
language plpgsql as $function$
begin
return date_trunc('year', to_date((to_char(coalesce($1, current_timestamp), 'YYYY-MM-DD')), 'YYYY-MM-DD'));
end
$function$;
<!DOCTYPE HTML>
<html>
<h1>
<form action="index.php" method="post">
Имя: <input type="text" name="username" value="<?php echo htmlspecialchars($_POST["name"]??''); ?>" /><br />
Email: <input type="text" name="email" value="<?php echo htmlspecialchars($_POST["email"]??''); ?>" /><br />
<input type="submit" name="submit" value="Отправь меня!" />
</form>
</h1>
</html>
SELECT (
SELECT sum(wp_postmeta.meta_value) AS result
FROM wp_posts
JOIN wp_postmeta ON wp_postmeta.post_id = wp_posts.ID
WHERE wp_posts.post_status='publish' and wp_posts.post_type='zakazy-tsekha'
AND wp_postmeta.meta_key='summa_zakaza'
) - (
SELECT sum(wp_jet_cct_raskhody.tsena_raskhoda)
FROM wp_jet_cct_raskhody
) AS result
$gorod = 'Moscow';
$query = "SELECT * FROM my WHERE gorod LIKE ?";
// get DB data using PDO
$stmt = $pdo->prepare($query);
$filter = "%$gorod%";
$stmt->execute([$filter]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($rows);