我成功地完成了第一个查询,但第二个查询不起作用
select order_id, firstname, lastname, phone, address, product, price, qty, subtotal, downpayment, total
from order_item, order_user on order_user.id = order_item.order_id
我试过这个,但它不起作用
select order_id, firstname, lastname, phone, address, product, price, qty, subtotal, downpayment, total
from order_item, order_user
where order_user.id = order_item.order_id where date >= '" + startdate.ToString() + "' AND date <= '" + enddate.ToString() + "'
您的错误在于您在查询语句中使用了两次 where。这是不允许的。另请注意,用于比较的日期格式是yyyy-MM-dd
格式。
下面的查询应该可以解决您的问题:
select order_id, firstname, lastname, phone, address, product, price, qty, subtotal, downpayment, total
from order_item, order_user
where order_user.id = order_item.order_id and date >= '2020-06-05' and date <= '2020-06-14'
似乎您正在 c# 代码中生成查询。
若要在 C# 中创建查询,可以使用以下代码:
string query = @"select order_id, firstname, lastname, phone, address, product, price, qty, subtotal, downpayment, total
from order_item, order_user
where order_user.id = order_item.order_id and date >= '" + startDate.ToString("yyyy-MM-dd") + "' and date <= '" + endDate.ToString("yyyy-MM-dd") + "'"