select BSproduct from
( -- Список продуктов имеющих черный цвет и малый размер
select product as BSProduct from
(
SELECT t1.id, t1.name AS product, t3.name AS color, t5.name AS size
FROM `product` AS t1
JOIN `product_color` AS t2 ON t1.id = t2.product_id
JOIN `color` AS t3 ON t2.color_id = t3.id
JOIN `product_size` AS t4 ON t1.id = t4.product_id
JOIN `size` AS t5 ON t4.size_id = t5.id
) as nested1
where color = "black" and size = "S"
) as BlackAndSmallSize,
( -- Список продуктов имеющих черный цвет и средний размер
select product as BMProduct from
(
SELECT t1.id, t1.name AS product, t3.name AS color, t5.name AS size
FROM `product` AS t1
JOIN `product_color` AS t2 ON t1.id = t2.product_id
JOIN `color` AS t3 ON t2.color_id = t3.id
JOIN `product_size` AS t4 ON t1.id = t4.product_id
JOIN `size` AS t5 ON t4.size_id = t5.id
) as nested2
where color = "black" and size = "M"
) as BlackAndMidSize,
( -- Список продуктов имеющих большой размер
select product as LProduct from
(
SELECT t1.id, t1.name AS product, t3.name AS color, t5.name AS size
FROM `product` AS t1
JOIN `product_color` AS t2 ON t1.id = t2.product_id
JOIN `color` AS t3 ON t2.color_id = t3.id
JOIN `product_size` AS t4 ON t1.id = t4.product_id
JOIN `size` AS t5 ON t4.size_id = t5.id
) as nested3
where size = "L"
) as LargeSize
where BSProduct=BMProduct and BMProduct=LProduct
old_id = 0;
imgpath = '';
meta='';
(S as SQLQuery).new.open('select ads.id, ads_meta.text, ads_images.path ...
from ads, ads_images, ads_meta
where ads_images.ads_id=ads.id and ads_meta.ads_id=ads.id
order by ads.id');
while (S.NextRecord) {
new_id = S.FieldToInt('ads.id');
if (new_id <> old_id) {
Сделаем что-надо с сформированным объявлением, у которого есть уже все пути и меты в imgpath и meta
imgpath = S.FieldToString('path');
meta = S.FieldToString('text');
}
else {
imgpath += ';' + S.FieldToString('path');
meta += chr(10) + chr(13) + S.FieldToString('text');
}
}
if 1==1 {s++};
StatusType (Id, StatusName) например( 1, друзья),(2, враги), (3, знакомые), (4, супруги) ...
Status(UserFromId, UserToId, StatusId,DateStart,DateEnd ... ) - первые 2 поля ссылаются на Users, 3-е на StatusType
Но, возможно, это не нужно и слишком усложнит все.