SELECT product_id FROM(
SELECT DISTINCT p.product_id, pd.name, p.model, p.quantity, p.price, p.sort_order, p.date_added , p.price as realprice
FROM oc_product p
LEFT JOIN oc_product_option_value pov ON pov.product_id = p.product_id
LEFT JOIN oc_product_description pd ON pd.product_id = p.product_id
LEFT JOIN oc_product_to_store p2s ON p2s.product_id = p.product_id
LEFT JOIN oc_product_to_category p2c ON p2c.product_id = p.product_id
LEFT JOIN oc_category_path cp ON cp.category_id = p2c.category_id
LEFT JOIN oc_product_attribute p2 ON p2.product_id = p.product_id
WHERE 1 AND cp.path_id IN (3558)
AND (
(p2.attribute_id = 12 AND p2a0.text LIKE '%ЛПО%') OR
(p2a1.attribute_id = 20 AND p2a1.text LIKE '%2х36 Вт%') OR
(p2a2.attribute_id = 22 AND p2a2.text LIKE '%накладны%') OR
(p2a3.attribute_id = 27 AND p2a3.text LIKE '%60 см%') OR
(p2a4.attribute_id = 29 AND p2a4.text LIKE '%T8%') OR
(p2a5.attribute_id = 30 AND p2a5.text LIKE '%220 В%')
)
AND pd.language_id = '1' AND p.status = '1' AND p2s.store_id = 0) as innertable
WHERE 1 ORDER BY sort_order ASC, LCASE(name) ASC LIMIT 0,20
SELECT u.id,
u.name,
IFNULL(SUM(o.amount), 0) AS full_amount,
SUM((SELECT FNULL(SUM(i.qty), 0) FROM `order_items` i where i.order_id = o.id )) full_quantity
FROM `users` u
LEFT JOIN `orders` o ON u.id = o.user_id
--Where кучей фильтров(условий)
GROUP BY u.id, u.name
SELECT DATE_FORMAT(`created_at`, '%y-%m-%d') as`created_at`,
SUM(CASE WHEN updated_at is null THEN 1 ELSE 0 END) AS "created_at_count",
SUM(CASE WHEN updated_at is not null THEN 1 ELSE 0 END) AS "updated_at_count"
FROM `table`
GROUP BY DATE_FORMAT(`created_at`, '%y-%m-%d')
SELECT DATE_FORMAT(`created_at`, '%y-%m-%d') as`created_at`,
SUM(1) AS "created_at_count",
SUM(CASE WHEN updated_at is not null THEN 1 ELSE 0 END) AS "updated_at_count"
FROM `table`
GROUP BY DATE_FORMAT(`created_at`, '%y-%m-%d')
SELECT DATA,
SUM(CASE WHEN USER_ID = 1 AND TYPE = 'add'
THEN 1 ELSE 0 END) AS ADD,
SUM(CASE WHEN USER_ID = 1 AND TYPE = 'remove'
THEN 1 ELSE 0 END) AS REMOVE
FROM ACTIONS
WHERE CREATED_AT > UNIX_TIMESTAMP(DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY))
GROUP BY DATA
не группирует по entities.id. Почему?
SELECT `date`, COUNT(*) AS cnt, 'tot_user' as user FROM `l_sites` GROUP BY `date`
union all
SELECT `date`, COUNT(*) AS cnt, 'tot_user2' as user FROM `l_users` GROUP BY `date`
union all
SELECT `date`, COUNT(*) AS cnt, 'tot_user3' as user FROM `l_leads` GROUP BY `date`
SELECT case when CHARACTER_LENGTH(TEXT) - CHARACTER_LENGTH(REPLACE(TEXT, '"', '')) = 2
then SUBSTRING(TEXT FROM LOCATE('"', TEXT)+1 FOR CHARACTER_LENGTH(TEXT) - LOCATE('"', TEXT)-1)
when CHARACTER_LENGTH(TEXT) - CHARACTER_LENGTH(REPLACE(TEXT, '"', '')) = 3
then SUBSTRING(TEXT FROM LOCATE('"', TEXT,LOCATE('"', TEXT)+1)+1 FOR CHARACTER_LENGTH(TEXT)-LOCATE('"', TEXT,LOCATE('"', TEXT)+1)-1 )
when CHARACTER_LENGTH(TEXT) - CHARACTER_LENGTH(REPLACE(TEXT, '"', '')) = 4
then SUBSTRING(TEXT FROM LOCATE('"', TEXT,LOCATE('"', TEXT)+1)+1 FOR CHARACTER_LENGTH(TEXT)-LOCATE('"', TEXT, LOCATE('"', TEXT,LOCATE('"', TEXT)+1)+1)-2)
else null
end
FROM mytable
select case when CHARACTER_LENGTH(TEXT) - CHARACTER_LENGTH(REPLACE(TEXT, '"', '')) = 2
then SUBSTRING_INDEX(SUBSTRING_INDEX(TEXT, '"', 2), '"', -1)
when CHARACTER_LENGTH(TEXT) - CHARACTER_LENGTH(REPLACE(TEXT, '"', '')) > 2
then SUBSTRING_INDEX(SUBSTRING_INDEX(TEXT, '"', 3), '"', -1)
else null
end
FROM mytable