with test as (select id_access, sum(1) as close
from Close where status = 0
group by id_access)
select S.*, Atr.name AS Aname, SUM("limit") AS limit,
sum( t.close), sum("limit") - sum(t.close)
from Schedule S
join Attribute Atr ON Atr.id_schedule = S.id
join Access Acc on Acc.id_attribute = Atr.id
left join test t on Acc.id = t.id_access
group by Atr.name, S.id, S.name
<?php
$json = <какой то json>;
$mapstats = json_decode($json, true);
$totalUsed = 0;
foreach ($mapstats as $i) {
$totalUsed += $i['usageCount'];
}
$data = [];
foreach ($mapstats as $value) {
$data[] = [
"name" => $value["map"],
"y" => $value["usageCount"] / $totalCount * 100
];
}
echo json_encode($data);
WITH t AS (SELECT *, row_number() over (PARTITION BY id ORDER BY created_at) as row FROM temporary_data),
d AS (SELECT DISTINCT ON (id) * FROM current_data ORDER BY id, created_at DESC)
SELECT t.*
FROM t
LEFT JOIN t t2 ON t.id = t2.id AND t.row = t2.row+1
LEFT JOIN d ON t.row = 1 AND t.id = d.id
WHERE t.value <> coalesce(t2.value, d.value);
INSERT INTO users (balance, steamid, name, avatar)
VALUES (0, $1, $2, $3)
ON CONFLICT (steamid) DO
UPDATE SET name = excluded.name,
avatar = excluded.avatav;