select si.total
from sales_inv si,c nf_order co
where si.order_num=co.order_no
and co.cnf_no='CNF001'
and co.added_on
between '$month1' and '$month2'
在此查询中,我想从表sales_inv
中获取销售发票中的order_num
和order_number
中的cnf_order
应该相等的总数。
added_on
是一个时间戳,应该在$month1
和$month2
之间
$month1
和$month2
是以时间戳格式存储数月的变量
这个查询不起作用,我做错了什么?
答案 0 :(得分:0)
select si.total
from sales_inv si,c nf_order co
where si.order_num=co.order_no
and co.cnf_no='CNF001'
and ( co.added_on
between '$month1' and '$month2')
编辑: -
使用日期功能
select si.total
from sales_inv si,c nf_order co
where si.order_num=co.order_no
and co.cnf_no='CNF001'
and ( DATE(co.added_on)
between DATE('$month1') and DATE('$month2'))
答案 1 :(得分:0)
尝试:
select si.total
from sales_inv si,c nf_order co
where si.order_num=co.order_no
and co.cnf_no='CNF001'
and co.added_on
between STR_TO_DATE('$month1', '%Y-%m-%d') and STR_TO_DATE('$month2', '%Y-%m-%d')