SELECT OutlayNames.name, SmetaOut.IdCategories, SUM(SmetaOut.cash)
FROM SmetaOut, OutlayNames
WHERE ( (month(SmetaOut.date) = month(GETDATE())) and (SmetaOut.cash<>0) and (OutlayNames.Id=SmetaOut.IdCategories))
GROUP BY OutlayNames.name, SmetaOut.IdCategories
//где находится клиент
$lat = клиент latitude;
$lng = клиент longitude;
//sql-запрос
SELECT
ROUND(
6371 * ACOS(SIN( $lat *PI()/180 ) * SIN( $lat *PI()/180 )
+ COS( $lat *PI()/180 ) * COS( $lat *PI()/180 ) * COS( ($lng*PI()/180) - ($lng*PI()/180) ) )
, 1) AS distance,
latitude,
longitude
FROM
your_table
ORDER BY distance ASC
LIMIT 8
;
select *
from
(
select
p.email,
cr.character_name,
cs.class_name
from players p
inner join characters cr on cr.player_id = p.id
inner join classes cs on cs.id = cr.class_id
)
pivot
(
MAX(character_name)
for class_name in ('Priest' as "Priest",
'Mage' as "Mage",
'Warrior' as "Warrior",
'Rogue' as "Rogue")
)
select
p.email,
decode(class_name, 'Priest', character_name, null) as "Priest",
decode(class_name, 'Mage', character_name, null) as "Mage",
decode(class_name, 'Warrior', character_name, null) as "Warrior",
decode(class_name, 'Rogue', character_name, null) as "Rogue"
from players p
inner join characters cr on cr.player_id = p.id
inner join classes cs on cs.id = cr.class_id
SELECT
s.name
,sum(r.value)
FROM sites as s
LEFT JOIN reviews as r ON s.id = r.id_site
GROUP BY s.id