mysql计算几列

时间:2014-03-25 02:08:14

标签: mysql database

我有一个包含以下查询的当前数据库:

表名:service 字段:service_id,name,labor_hour,part_cost,rate_id

`service_id` as `primary key`


rate_id as foreign key references rate(rate_id)

率(rate_id,labor_cost_per_hour)     主键(rate_id)

表名:order_service 字段:

order_service_id,order_id,service_id
    order_service_id as primary key
    order_id as foreign key references order(order_id)
    service_id as foreign key references service(service_id)

service cost = labor hours * labor cost per hour + part cost

我想列出其service idcost of services超过一定数量的costs和{{1}}。 我不知道如何计算mysql中的服务成本;我想过内联两个表,但似乎不行。有谁会给我一些帮助?谢谢!

1 个答案:

答案 0 :(得分:1)

尝试这样

select service_id,(labor hours * labor cost per hour + part cost) from 
service s INNER JION  
rate r ON r.rate=s.rate 
where  (labor hours * labor cost per hour + part cost) > 500