$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 "Заявка сохранена в системе";
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;
SELECT
companyName,
PriceAvg
FROM
(
SELECT
`companyId`,
AVG(`price`) AS PriceAvg
FROM
phone
GROUP BY
`companyId`
) AS reporttable
INNER JOIN company ON reporttable.companyId = company.companyId
ORDER BY PriceAvg DESC LIMIT 1;
ALTER TABLE jshopping_orders ADD COLUMN IF NOT EXISTS bonus varchar(24) NOT NULL DEFAULT '';
SELECT
GROUP_CONCAT('select "' || name || '" table_name, * from `' || name || '` where referer = "yandex"', ' union ') q
FROM
sqlite_master
WHERE
type ='table' AND
name NOT LIKE 'sqlite_%';
select "t1" table_name, * from t1 where referer = "yandex" union select "t2" table_name, * from t2 where referer = "yandex"
+============+====+=========+
| table_name | id | referer |
+============+====+=========+
| t1 | 2 | yandex |
+------------+----+---------+
| t2 | 20 | yandex |
+------------+----+---------+
select dates.date_time dates, count(distinct tbl.user_id), sum(tbl.price)
from (
select distinct date(tbl.date_time) date_time from tbl
) dates
join tbl on dates.date_time >= date(tbl.date_time)
group by dates.date_time
order by dates.date_time;
$stmt = $conn->prepare(
"UPDATE `sortlist`
SET
`count1` ='count1' + ? ,
`count2` ='count2' + ? ,
`count3` ='count3' + ?
WHERE `id`= ? ;"
);
$stmt->bind_param('iiis', $count1, $count2, $count3, $row);
foreach ($data as $value) {
list($row, $col) = explode("-", $value['id']);
$count1 = 0;
$count2 = 0;
$count3 = 0;
$column = "count" . intval($col);
$$column = $value["count"];
echo "$count1, $count2, $count3, $row";
$stmt->execute();
}
DELETE FROM dle_comments
WHERE NOT EXISTS (SELECT 1 FROM dle_post WHERE dle_post.id = dle_comments.post_id);
DELETE dle_comments.*
FROM dle_comments
LEFT JOIN dle_post ON dle_post.id = dle_comments.post_id
WHERE dle_post.id IS NULL;
SELECT * FROM `action` WHERE `condition` LIKE '%"action": "6"%';
SELECT
orders.num, orders.createdon, orders.cost, orders.status,
GROUP_CONCAT(products.name) prod_names,
GROUP_CONCAT(products.count) prod_counts,
GROUP_CONCAT(products.cost) prod_costs
FROM `modx_ms2_orders` AS orders
JOIN `modx_ms2_order_products` AS products ON orders.id = products.order_id
WHERE `user_id` = 106
GROUP BY orders.num, orders.createdon, orders.cost, orders.status
SELECT
COUNT(case when d.created_at > NOW() - interval '7 days' then 1 else null end) as "7 days",
COUNT(case when d.created_at > NOW() - interval '14 days' then 1 else null end) as "14 days",
COUNT(case when d.created_at > NOW() - interval '1 month' then 1 else null end) as "1 month"
c.short_name
FROM documents_owners dow
INNER JOIN contractors_main c ON dow.contractor_id = c.id
INNER JOIN documents_main d ON dow.document_id = d.id
GROUP BY c.short_name
ORDER BY COUNT(dow.document_id) DESC
with sqlite3.connect('base.db') as conn:
cursor = conn.cursor()
cursor.execute(f"UPDATE inv SET nabor = json_replace(nabor, '$.id', 99) WHERE ids={ctx.author.id}")
con.commit()
SELECT
Site_id, url,
COUNT(DISTINCT site_area.site_area_id) active_blocks,
SUM(impression_count) impression_count,
SUM(revenue) revenue
FROM site
JOIN site_area USING(site_id)
LEFT JOIN npm_site_area_stat_cache USING(site_area_id)
WHERE site_area.status = 1
GROUP BY site_id, url
HAVING COUNT(DISTINCT site_area.site_area_id) > 3;
SELECT
pn.country, array_agg(s.name) services
FROM number pn
CROSS JOIN service s
LEFT JOIN buy_number bn ON bn.numberId = pn.id AND bn.serviceId = s.id
WHERE bn.id is NULL
GROUP BY pn.country;
SELECT
`authors`.`id`, `authors`.`last_name`, `authors`.`first_name`, COUNT(*) `author_count`
FROM `bookissue`
JOIN `books` ON `books`.`id` = `bookissue`.`idBook`
JOIN `authors` ON `authors`.`id` = `books`.`idAuthor`
WHERE YEAR(`bookissue`.`data`) = ?
GROUP BY `authors`.`id`, `authors`.`last_name`, `authors`.`first_name`
ORDER BY `author_count` DESC
LIMIT 1