比较表之间的值

时间:2014-03-01 10:48:17

标签: mysql select

目标:我有3个表,每个表都有相同的字段名称。如果销售价值超过某些条件,我想在第4个表格中添加第3个表格中的值 类似的东西:

INSERT INTO table4 (int, den, prod, sales, ut, stoc)
SELECT int, den, prod, sales, ut, stoc FROM table3 
WHERE (0 < table1.sales) AND (table1.sales < table2.sales) \
       AND (table2.sales < table3.sales) 

由于

1 个答案:

答案 0 :(得分:0)

试试这个

INSERT INTO table4 (`int`, den, prod, sales, ut, stoc)
SELECT T3.`int`, T3.den, T3.prod, T3.sales, T3.ut, T3.stoc 
FROM table3 T3 INNER JOIN table1 T1 ON (T1.sales > 0)
INNER JOIN Table2 T2 ON (T1.sales < T2.sales) AND (T2.sales < T3.sales)