SELECT
(SELECT COUNT(a.`id`) FROM `marks` AS a WHERE a.`value` IN ("Отлично")) AS `count_5`,
(SELECT COUNT(b.`id`) FROM `marks` AS b WHERE b.`value` IN ("Хорошо", "Отлично")) AS `count_4_5`,
(SELECT COUNT(c.`id`) FROM `marks` AS c WHERE c.`value` IN ("Удов.", "Хорошо", "Отлично")) AS `count_3_4_5`
SELECT
a.*,
b.*,
c.*
FROM
`contacts` AS a
LEFT JOIN
`users_app` AS b
ON
b.id = a.id_contact
LEFT JOIN
`messages` AS c
ON
c.`id` =
(
SELECT
MAX(d.id)
FROM
`messages` AS d
WHERE
(
d.id_user = a.id_user
AND
d.id_from_user = a.id_contact
)
OR
(
d.id_user = a.id_contact
AND
d.id_from_user = a.id_user
)
)
WHERE
a.id_user = $id_user
<?php
$skip = (max($page, 1) - 1) * 10
$sql = 'SELECT `id` FROM `articles` WHERE `raz`='1' ORDER BY `id` DESC limit '. $skip .', 10';
?>
SELECT
a.`user_id`,
b.`user_name`,
a.`date`,
a.`value`
FROM
`values` AS a
JOIN
`users` AS b
ON
b.`user_id` = a.`user_id`
WHERE
a.`date` = "26.12.2014"
AND
a.`value` >
(
SELECT
c.`value`
FROM
`values` AS c
WHERE
c.`user_id` = a.`user_id`
AND
c.`date` = "25.12.2014"
LIMIT 1
)
INSERT INTO tbl_name (col1,col2) VALUES ($val1_1, $val1_2), ($val2_1, $val2_2), ...,($valN_1, $valN_2);
// Сохранение данных в БД
for($a = 0, $b = count($metrika->data); $a < $b; $a++){
// ....
}