[问]加入两张桌子

时间:2016-05-23 05:20:52

标签: php mysql

第一次查询

SELECT material_name,material_type,original,vr,repro,scrap FROM stock_opname

有88个结果

第二次查询

  SELECT t.material_name,t.material_type, 
         (SELECT SUM(qty) FROM temp_data_transaction where material_name=t.material_name and destination = 'WAREHOUSE_RESIN' and kind_of_transaction = 'ORIGINAL') as 'total_original',
         (SELECT SUM(qty) FROM temp_data_transaction where material_name=t.material_name and destination = 'WAREHOUSE_RESIN' and kind_of_transaction = 'VR') as 'total_vr', 
         (SELECT SUM(qty) FROM temp_data_transaction where material_name=t.material_name and destination = 'WAREHOUSE_RESIN' and kind_of_transaction = 'SCRAP') as 'total_scrap', 
         (SELECT SUM(qty) FROM temp_data_transaction where material_name=t.material_name and destination = 'WAREHOUSE_RESIN' and kind_of_transaction = 'REPRO') as 'total_repro',
         (SELECT SUM(qty) FROM temp_data_transaction where material_name=t.material_name and source = 'WAREHOUSE_RESIN' and kind_of_transaction = 'ORIGINAL') as 'total_original_out',
         (SELECT SUM(qty) FROM temp_data_transaction where material_name=t.material_name and source = 'WAREHOUSE_RESIN' and kind_of_transaction = 'VR') as 'total_vr_out', 
         (SELECT SUM(qty) FROM temp_data_transaction where material_name=t.material_name and source = 'WAREHOUSE_RESIN' and kind_of_transaction = 'REPRO') as 'total_repro_out',
         (SELECT SUM(qty) FROM temp_data_transaction where material_name=t.material_name and source = 'WAREHOUSE_RESIN' and kind_of_transaction = 'SCRAP') as 'total_scrap_out'
         FROM temp_data_transaction t GROUP BY material_name

有6个结果

问题 如何在查询中加入查询二?

感谢

0 个答案:

没有答案