有3张表
Orders
字段有
id,orders_No,customer_id,confirm_date,is_paidOrders_Details字段有
id,orders_No,product_id,cat_id,Product
字段有
id,product_name要求是这样的
从Orders表根据confirm_date时间去查询出某一时间段符合条件的orders_No
然后用获取到的orders_No查询Orders_Details 并且根据cat_id字段查询 获取product_id
根据product_id查询Product这张表 要求只用一个SQL语句求高手们帮帮忙 在线等答案
Orders
字段有
id,orders_No,customer_id,confirm_date,is_paidOrders_Details字段有
id,orders_No,product_id,cat_id,Product
字段有
id,product_name要求是这样的
从Orders表根据confirm_date时间去查询出某一时间段符合条件的orders_No
然后用获取到的orders_No查询Orders_Details 并且根据cat_id字段查询 获取product_id
根据product_id查询Product这张表 要求只用一个SQL语句求高手们帮帮忙 在线等答案
from Orders a
left join Orders_Details b on a.orders_No = b.orders_No
left join Product c on c.id = b.product_id
where a.confirm_date = '你的条件' and b.cat_id = ‘你的条件’不知楼主是不是这意思?
select p.* from Orders o
inner join Orders_Details d on d.orders_No = o.orders_No
inner join Product p on d.product_id = p.id
from Orders a
left join Orders_Details b on a.orders_No = b.orders_No
left join Product c on c.id = b.product_id
where a.confirm_date >= '你的条件开始日期' + ' 0:00:00' and a.confirm_date >= '你的条件结束日期' + '23:59:59' and b.cat_id = ‘你的条件’
from Orders a
inner join Orders_Details b on a.orders_No = b.orders_No
inner join Product c on c.id = b.product_id
where (a.confirm_date between '开始时间' and '结束时间') and b.cat_id = ‘XX’
如果日期 比较符号是 >= <= between 的话,就不用格式化直接比较就行了如果日期 比较符号是 = 就这样格式化吧 Select CONVERT(varchar(100),日期, 112),格式为
20100605