这就是我想要做的。我想看看,在一定的价格和成本的基础上,我的利润是多少。下面是一个例子:
SELECT price, cost, profit,
price-5 "price1", cost, price-5-cost "profit1"
FROM table
WHERE product = blue_pants; 这将显示如下数据:
price cost profit price1 cost profit1 我希望是这样的:
price cost profit
price1 cost profit1 这就是我想要的数据显示的方式。这有意义吗?有没有办法做到这一点。对不起,我是SQL菜鸟。
发布于 2013-06-05 06:56:01
Select price, cost, profit
From table
Where product = 'blue_pants'
Union All
Select price-5, cost, price-5-cost
From table
Where product = 'blue_pants'这显然会重复行。为了知道哪些行应该出现在第一个查询中,哪些应该出现在第二个查询中,我们需要知道条件(例如Where price-5 > 0)。
https://stackoverflow.com/questions/16928772
复制相似问题