SELECT t1.post_id, SUM(t1.dl)
FROM wp_day_download t1
INNER JOIN wp_term_relationships t2 ON t2.object_id = t1.post_id
INNER JOIN wp_term_taxonomy t3 ON t3.term_taxonomy_id = t2.term_taxonomy_id
AND t3.term_id = 179
WHERE t1.date >= DATE_ADD(CURRENT_TIMESTAMP,INTERVAL -7 DAY)
GROUP BY t1.post_id
SELECT Train.nameTrain, Trip.time as date,
Passanger.firstname, Passanger.lastname, Passanger.birthday,
Price.wagon, Ticket.place, Price.price,
Ticket.departureStation, Ticket.arrivalStation,
dst.nameStation as dep, ast.nameStation as arr
FROM Ticket
JOIN Trip
ON Ticket.idTrip = Trip.idTrip
JOIN Passanger
ON Ticket.idPassanger = Passanger.idPassanger
JOIN Train
ON Trip.idTrain = Train.idTrain
JOIN Price
ON Train.idTrain = Price.idTrain AND Ticket.wagon = Price.wagon
JOIN Station dst
ON Ticket.departureStation = dst.idStation
JOIN Station ast
ON Ticket.arrivalStation = ast.idStation
select
usr.*,
recept.*
from
(
select distinct
t2.*
from tovary t1
inner join recepty t2 on t2.product_use_1 = t1.id
or t2.product_use_2 = t1.id
or t2.product_use_3 = t1.id
// и тд до t2.product_use_9
where t1.id = ####
) as recept
inner join
(
select
t1.id,
t1.name,
t2.own_id
from
users t1
inner join comments t2 on t1.id = t2.own_id
) as usr on usr.own_id = recept.own_id
select
t.'Display Name',
t.'Course',
t.'Category',
t.'Item Name',
MAX(CASE WHEN t.'idnumber' = 'a1' THEN t.'Grade' ELSE NULL END) AS 'оценка А',
MAX(CASE WHEN t.'idnumber' = 'b1' THEN t.'Grade' ELSE NULL END) AS 'оценка Б'
// и так далее: c1,d1 и t1
from
(
// ВАШ ЗАПРОС, добавил - gg.idnumber AS 'idnumber'
SELECT u.firstname AS 'First' , u.lastname AS 'Last', u.firstname + ' ' + u.lastname AS 'Display Name',
c.fullname AS 'Course',
cc.name AS 'Category',
CASE
WHEN gi.itemtype = 'course'
THEN c.fullname + ' Course Total'
ELSE gi.itemname
END AS 'Item Name',
ROUND(gg.finalgrade,2) AS Grade,
gg.idnumber AS 'idnumber'
FROM prefix_course AS c
JOIN prefix_context AS ctx ON c.id = ctx.instanceid
JOIN prefix_role_assignments AS ra ON ra.contextid = ctx.id
JOIN prefix_user AS u ON u.id = ra.userid
JOIN prefix_grade_grades AS gg ON gg.userid = u.id
JOIN prefix_grade_items AS gi ON gi.id = gg.itemid
JOIN prefix_course_categories AS cc ON cc.id = c.category
WHERE gi.courseid = c.id
ORDER BY lastname
) t
group by t.'Display Name',
t.'Course',
t.'Category',
t.'Item Name'
select
t1.*,
t3.name
from
product t1
inner join (
select
product_id
from product_size
inner join size on id = size_id
where name in ('S', 'M', 'L')
group by product_id
having count(product_id) = 3
) t2 on t2.product_id = t1.id
inner join (
select
product_id
,name
from product_color
inner join color on id = color_id
where name = 'black'
) t3 on t3.product_id = t2.product_id
SELECT COUNT(*) as t1_count, NULL FROM `table_1` WHERE `id`='7'
UNION
SELECT NULL, COUNT(*) as t2_count FROM `table_2` WHERE `id`='7'
select
COUNT(*) as t1_count,
t2.t2_count
FROM `table_1` t1
inner join
(
SELECT id, COUNT(*) as t2_count FROM `table_2` WHERE `id`='7'
) t2 on t2.id = t1.id
where t1.id = '7'