php – Mysql内部加入查询

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – Mysql内部加入查询脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_403_1@
我是MySQL查询新手.

我有2个表(tbl1,tbl2)

我需要以start_time升序加入这两个表并过滤日期和emp_id

这里的表格字段不同(开始时间 – >及时,结束时间 – >输出时间)

tbl-1:

id      start-time      end-time        date            emp_id

1       09:00:00        09:00:59        2014-05-14        1

2       10:00:00        10:00:59        2014-05-14        1

3       12:00:00        12:00:59        2014-05-14        1

4       14:00:00        14:00:59        2014-05-14        1

5       16:00:00        17:00:59        2014-05-13        1


tbl-2:

id      in-time         out-time        date            emp_id

1       11:00:00        11:00:59        2014-05-14        1

2       13:00:00        13:00:59        2014-05-14        1

3       15:00:00        15:00:59        2014-05-14        1

4       18:00:00        19:00:59        2014-05-14        2

5       20:00:00        20:00:59        2014-05-15        1


filterd by date,emp_id ordered by date

result-tbl:

id      start-time      end-time        date            emp_id

1       09:00:00        09:00:59        2014-05-14        1

2       10:00:00        10:00:59        2014-05-14        1

3       11:00:00        11:00:59        2014-05-14        1

4       12:00:00        12:00:59        2014-05-14        1

5       13:00:00        13:00:59        2014-05-14        1

6       14:00:00        14:00:59        2014-05-14        1

7       15:00:00        15:00:59        2014-05-14        1

解决方法

我不认为你想加入.我想你想要一个工会以及重新分配id的方法.就像是:

select (@rn := @rn + 1) as id,intime as starttime,outtime as outtime,emp_id
From ((select * from tbl1)
      union all
      (select * from tbl2)
     ) t cross join
     (select @rn := 0) VAR
where emp_id = 1 and
      intime <= '18:00:00'
order by intime;

脚本宝典总结

以上是脚本宝典为你收集整理的php – Mysql内部加入查询全部内容,希望文章能够帮你解决php – Mysql内部加入查询所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。