更改mysql查询以返回始终结果

时间:2015-11-02 07:21:22

标签: php mysql

我有这个查询检查与所显示的一个产品相关的(类似的),如果有,它会显示它们。如果没有任何相关(类似)产品显示其他产品,如何更改它。这是查询:

   ggplot(allDTI, aes(x=values, color=type)) + 
      stat_ecdf(size=1, show_guide=T) + 
      xlab(expression('Index Value')) + 
      ylab("Cumulative Density") +
      ggtitle(expression(TI[d]~'and'~TI[l]~'and'~TI[w])) +
      scale_x_continuous(expand = c(0,0)) +
      scale_y_continuous(expand = c(0,0)) +
      theme(text = element_text(size=20),
            plot.title = element_text(size=30,face="bold",vjust=1),
            axis.title.x=element_text(size=20,face="bold",vjust=0,hjust=0.5),
            axis.title.y=element_text(size=20,face="bold",vjust=1.0,hjust=0.5),
            legend.position = c(0.85, 0.25),
            legend.text.align = 0,
            legend.box = 'horizontal',
            legend.margin = unit(45.0, 'line'),
            legend.text=element_text(size=28,vjust=0,hjust=0),
            legend.key.height = unit(1.5, 'line'),
            legend.key.width = unit(1.5, 'line'),
            panel.background = element_rect(fill = "white")) + 
      scale_color_manual(values=c('grey10','grey30','grey50'),
                         labels=c(expression(TI[d]),expression(TI[l]),
                                  expression(TI[w]))) +
      guides(color = guide_legend(title=NULL)) + 
      geom_vline(data=meanALLDTI, aes(xintercept=values.mean,  colour=type),
                 linetype="dashed", size=1, show_guide=T) + 
      scale_linetype_manual(values=c('grey10','grey30','grey50'),
                         labels=c(expression(bar(TI[d])),expression(bar(TI[l])),
                                  expression(bar(TI[w])))) +
      guides(linetype= guide_legend(title=NULL))

感谢您的任何帮助和建议!

2 个答案:

答案 0 :(得分:1)

使用左连接并输入" rp.product_id =" 10284""作为连接条件的条件不在哪里。

像 产品p left Join related_products rp ON rp.related_id = p.id AND rp.product_id =" 10284"

按照完整查询进行操作。

答案 1 :(得分:1)

试试这个

SELECT 
    p.id,bg_product_name,unique_name,product_price, promo_price, promo_end_date, 
    available_qty,model,ptc.category_id, free_delivery, free_option
FROM 
    products p
    LEFT OUTER JOIN products_to_categories ptc ON p.id=ptc.product_id
    LEFT OUTER JOIN related_products rp ON rp.related_id=p.id AND rp.product_id="10284"

WHERE
    p.available_qty > 0 AND p.active="1" 
GROUP BY p.id LIMIT 5