【发布时间】:2014-04-02 22:51:10
【问题描述】:
我有这些表:
reg_movs:
regmovs_id id_car date status
1 1 2014-02-02 16:00:00 0
2 1 2014-02-02 16:12:00 5
3 2 2014-02-02 16:22:03 0
4 2 2014-02-02 16:45:14 5
service_detail:
id id_Car date_updated price
1 1 2014-02-02 16:12:00 45.00
2 2 2014-02-02 16:45:14 30.00
我的意思是,当status=0 时,它会在我的SELECT QUERY 中设置开始时间。并且,当status=5 时,它将结束时间。
如何进行这样的查询:
id_car date start end price
1 2014-02-02 16:00:00 16:12:00 45.00
2 201-02-02 16:22:03 16:46:14 30.00
【问题讨论】:
-
不清楚您要达到的目标。你想要一个返回某种形式的结果集的
SELECT语句吗? -
这样的? SELECT start as time_somethingorother FROM reg_movs INNER JOIN service_detail USING (id_car) WHERE status=0 UNION SELECT end as time_somethingorother FROM reg_movs INNER JOIN service_detail USING (id_car) WHERE status=5