例如表A,有两列c1和c2。
表数据如下
 c1 c2
 3   4
 2   1
 8   2
c1-c2之后就是
 -1
 1
 6
然后把它们变成以下,只取大于0的:c1-c2之后就是
 1
 6请问怎么用sql语句来实现????

解决方案 »

  1.   

    SELECT * FROM (
    SELECT C1-C2 AS A1 FROM TT) A
    WHERE A1>0
      

  2.   

    select t.product_number,t.product_number_noc,count(*) as quantity,round(count(*)*1.3) as goumai,s.product_quantity,round(count(*)*1.3)-s.product_quantity as sult 
    from tworder_products t,products_stock s where t.import_date in 
    (select distinct(import_date) from(select distinct(import_date) from tworder_products order by import_date desc LIMIT 9) as result)
    and t.product_number != ''
    and t.product_number_noc = s.product_sku
    group by t.product_number其实我的整个sql是这样的
      

  3.   

    select t.product_number,t.product_number_noc,count(*) as quantity,round(count(*)*1.3) as goumai,s.product_quantity,round(count(*)*1.3)-s.product_quantity as sult 
    from tworder_products t,products_stock s where t.import_date in 
    (select distinct(import_date) from(select distinct(import_date) from tworder_products order by import_date desc LIMIT 9) as result)
    and t.product_number != ''
    and t.product_number_noc = s.product_sku
    group by t.product_number其实我的整个sql是这样的,我要sult的  取大于0的所有行我在下面加个and sult > 0   不能识别sult,求高手解决
      

  4.   

    select (select c1-c2 from A)b
    from A
    WHERE A.b>0;
      

  5.   

    select c1-c2 from a where c1>c2;