我试图展示一个" YES"如果值包含信息:
我在这里与id_order建立了关系:
LEFT JOIN ps_surchage_eq_orders re ON a.`id_order`=re.`id_order`
如果当前" id_order"有这种关系的任何数据,它可以显示值"是"?
SELECT SQL_CALC_FOUND_ROWS DISTINCT a.`id_order`, a.`invoice_number` AS num_factura,a.`delivery_number` AS num_albaran,a.`reference`, CONCAT(c.`firstname`, ' ', c.`lastname`) AS `customer`, c.email, addr.dni, gr.name AS group_name, a.total_discounts_tax_excl,a.total_paid_real, re.`id_order` AS RE, a.`payment`, a.`date_add` AS `date_add` , a.id_currency, a.id_order AS id_pdf, osl.`name` AS `osname`, IF((SELECT so.id_order
FROM `ps_orders` so
WHERE so.id_customer = a.id_customer AND so.id_order < a.id_order LIMIT 1) > 0, 0, 1) as new, country_lang.name as cname, IF(a.valid, 1, 0) badge_success
FROM `ps_orders` a
LEFT JOIN `ps_customer` c ON (c.`id_customer` = a.`id_customer`)
LEFT JOIN `ps_address` address ON address.id_address = a.id_address_delivery
LEFT JOIN `ps_country` country ON address.id_country = country.id_country
LEFT JOIN `ps_country_lang` country_lang ON (country.`id_country` = country_lang.`id_country` AND country_lang.`id_lang` = 1)
LEFT JOIN `ps_order_state` os ON (os.`id_order_state` = a.`current_state`)
LEFT JOIN `ps_order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = 1)
LEFT JOIN `ps_address` addr ON (c.id_customer=addr.id_customer)
LEFT JOIN ps_group_lang gr ON c.id_default_group=gr.id_group AND gr.id_lang=a.id_lang
LEFT JOIN ps_surchage_eq_orders re ON a.`id_order`=re.`id_order`
WHERE 1
ORDER BY a.`id_order` DESC
谢谢!
答案 0 :(得分:0)
将re.id_order AS RE
替换为IF(re.id_order IS NULL, 'YES', 'NO' ) AS RE
SELECT SQL_CALC_FOUND_ROWS DISTINCT a.`id_order`, a.`invoice_number` AS num_factura,a.`delivery_number` AS num_albaran,a.`reference`, CONCAT(c.`firstname`, ' ', c.`lastname`) AS `customer`, c.email, addr.dni, gr.name AS group_name, a.total_discounts_tax_excl,a.total_paid_real, IF(re.`id_order` IS NULL, 'YES', 'NO' ), a.`payment`, a.`date_add` AS `date_add` , a.id_currency, a.id_order AS id_pdf, osl.`name` AS `osname`, IF((SELECT so.id_order
FROM `ps_orders` so
WHERE so.id_customer = a.id_customer AND so.id_order < a.id_order LIMIT 1) > 0, 0, 1) as new, country_lang.name as cname, IF(a.valid, 1, 0) badge_success
FROM `ps_orders` a
LEFT JOIN `ps_customer` c ON (c.`id_customer` = a.`id_customer`)
LEFT JOIN `ps_address` address ON address.id_address = a.id_address_delivery
LEFT JOIN `ps_country` country ON address.id_country = country.id_country
LEFT JOIN `ps_country_lang` country_lang ON (country.`id_country` = country_lang.`id_country` AND country_lang.`id_lang` = 1)
LEFT JOIN `ps_order_state` os ON (os.`id_order_state` = a.`current_state`)
LEFT JOIN `ps_order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = 1)
LEFT JOIN `ps_address` addr ON (c.id_customer=addr.id_customer)
LEFT JOIN ps_group_lang gr ON c.id_default_group=gr.id_group AND gr.id_lang=a.id_lang
LEFT JOIN ps_surchage_eq_orders re ON a.`id_order`=re.`id_order`
WHERE 1
ORDER BY a.`id_order` DESC
如果ps_surchage_eq_orders没有那个id_order,它将为null,if将返回YES,如果它有,它将不为null并将返回NO