INSERT INTO table_1 (name, quantity)
VALUES ('Name1', 1), ('Name2', 1)
ON CONFLICT (name) DO UPDATE SET quantity = quantity + 1
;
UPDATE users x
SET step = 'confirmed'
FROM users y
WHERE x.number = y.number
AND x.number = 1
RETURNING y.number AS number, y.step AS old_step, x.step;
$stmt = $connection->prepare(
"SELECT * FROM users WHERE email = ? OR phone = ?"
);
$stmt->bind_param("ss", $email, $phone);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows() > 0) {
echo "Вы уже оставили заявку";
} else {
echo "Новая заявка";
}
CREATE TABLE users (
email varchar(255),
phone varchar(255),
UNIQUE KEY (email),
UNIQUE KEY (phone)
);
$stmt = $connection->prepare(
"INSERT INTO users (email, phone) VALUES (?, ?)"
);
$stmt->bind_param("ss", $email, $phone);
try {
$stmt->execute();
} catch (Exception $e) {
die("Вы уже оставили заявку");
}
echo "Заявка сохранена в системе";
update routes set
seq = if(trunk_id = 118, 0, trunk_id)
where route_id = 16;
update routes set
seq = if(trunk_id = 118, 0, seq+1)
where route_id = 16;
SELECT
prices.*
FROM
`prices`
JOIN (
SELECT size, MAX(date_time) date_time FROM prices GROUP BY size
) last_price USING (size, date_time)
WHERE
-- model_id = '269' AND partner_id = '0' AND
size <= '32'
AND date_time <= '2021-10-19'
AND price > 0
ORDER BY
size DESC,
date_time DESC;
SELECT * FROM (
SELECT
prices.*,
ROW_NUMBER() OVER (PARTITION BY size ORDER BY date_time DESC) last_price
FROM
`prices`
WHERE
-- model_id = '269' AND partner_id = '0' AND
size <= '32'
AND date_time <= '2021-10-19'
) data
WHERE last_price = 1 AND price > 0
ORDER BY
size DESC;
SELECT
SUM(ammount * (CASE WHEN idoperation = 1 THEN 1 ELSE -1 END)) AS result
FROM journal
;
SELECT query, COUNT(*) cont FROM (
SELECT
CASE
WHEN val LIKE '%111%' THEN '%111%'
WHEN val LIKE '%222%' THEN '%222%'
ELSE 'other'
END query
FROM tbl
WHERE val LIKE '%111%' OR val LIKE '%222%'
) tbl GROUP BY query;
+=======+======+
| query | cont |
+=======+======+
| %111% | 2 |
+-------+------+
| %222% | 1 |
+-------+------+
SELECT
id,
diff,
SUM(diff) OVER (ORDER BY id ASC)
FROM t;
START TRANSACTION;
delete from gift_certificate_to_tag_relation where gift_certificate_id = 1;
delete from gift_certificate where id = 1;
COMMIT;
// convert array to apopriate form
$name_colors = array_combine(
array_values($arr['name']),
array_values($arr['color']),
);
// print select options
foreach($name_colors as $name=>$color) {
printf('<option name="chapter" style="color:%s" class="user-chapters" >%s</option>'.PHP_EOL, $color, $name);
}
CREATE TABLE "TankContentStateHistory" (
"TankContentStateHistoryId" serial NOT NULL,
"AverageTemperature" double precision NOT NULL,
"GTVolume" double precision DEFAULT 0.0 NOT NULL
);
INSERT INTO "TankContentStateHistory" ("AverageTemperature", "GTVolume") VALUES (10, 20);
SELECT * FROM "TankContentStateHistory";
echo preg_replace('/\A\/\//i', 'https://', 'https://exzmple1.com');
echo preg_replace('/\A\/\//i', 'https://', '//www.example2.com');