select t1.some_field,
(select t2.value
from otherTable t2
where t2.name = t1.name
order by t2.value
limit 2, 1) as second_value,
(select sum(t2.value)
from otherTable t2
where t2.name = t1.name) as total_value
from table_1 t1
SELECT
*
FROM (SELECT
TYPE, MAX(DATE) AS DATE
FROM TABLE
INNER JOIN USERS ON USERS.ID = TABLE.ID
WHERE
USERS.NAME = 'Test'
GROUP BY
TYPE)
ORDER BY DATE DESC
SELECT
TYPE,
MAX(DATE) AS DT
FROM TABLE
INNER JOIN USERS ON USERS.ID = TABLE.ID
WHERE
USERS.NAME = 'Test'
GROUP BY
TYPE
ORDER BY DT DESC
SELECT
LOGIN,
SUM(IF(TYPE=0, SUM, 0)) OUT_COME,
SUM(IF(TYPE=1, SUM, 0)) IN_COME,
FROM
INFO_USER
GROUP BY
LOGIN