mysql加入返回完美的结果

时间:2016-06-08 05:36:41

标签: mysql

我已经买了两个VLSI电子学和VLSI extc课程 一起买,所以它有相同的订单ID 当我们搜索vlsi或电子设备时,查询返回结果 在filterextc中搜索时没有任何结果。

 SELECT  `i.*,r.emailid,r.first_name,u.university_name,ct.country_name,st.state_name, cy.city_name,r.address,r.mobile,COUNT( k.order_id ) as order_cnt, k.product_type AS product_type,k.product_id AS product_id,tx.tax_amount,str.stream_name,fie.field_name,sems.semester_number,colg.college_name,`
    IF( product_type =  "course", (SELECT course_title FROM tbl_courses WHERE course_id = product_id  AND course_title Like "%vlsi%"), 0 ) AS coursebought,
     IF(product_type = "module",(SELECT module_title FROM tbl_modules WHERE module_id = product_id ), 0 ) AS modulebought  
      FROM (`tbl_orders` AS i)
                      LEFT JOIN  tbl_users AS r ON  i.user_id =  r.user_id
                      LEFT JOIN  tbl_discount_history AS hd ON  i.order_id =  hd.order_id
                      AND i.discount_id = hd.discount_id
                      AND hd.status =  "Active"
                      LEFT JOIN  tbl_shopping_cart AS k ON  i.order_id = k.order_id 
                      LEFT JOIN  tbl_university AS u ON  u.university_id =  r.university_id
                      LEFT JOIN  tbl_country AS ct ON  u.country_id =  ct.country_id
                      LEFT JOIN  tbl_states AS st ON  u.state_id =  st.state_id
                      LEFT JOIN  tbl_city AS cy ON  u.city_id =  cy.city_id
                      LEFT JOIN  tbl_finalorder_tax_details AS tx ON  i.order_id =  tx.order_id
                      LEFT JOIN  tbl_stream AS str ON  r.stream_id =  str.stream_id
                      LEFT JOIN  tbl_fields AS fie ON  r.field_id  =  fie.field_id
                      LEFT JOIN  tbl_semester_type AS sems ON  r.semester_id  =  sems.semester_id
                      LEFT JOIN  tbl_colleges AS colg ON  r.college_id  =  colg.college_id
                      and ct.country_id =  cy.city_country_id
                      and st.state_id =  cy.city_state_id
                      WHERE tx.tax_id = 1 and r.status =  "Active" And 1=1   AND product_id IS NOT NULL 
                      AND product_type =  "course"
                      GROUP BY order_id 
                      having coursebought IS NOT NULL and modulebought IS NOT NULL 
                      ORDER BY  order_id  desc 
                      limit 0,10

0 个答案:

没有答案