我必须加入三个表。加入三个表的sql查询
1表是交易,下表是商店,3是天气。
我想从所有这三个数据中获取数据,但是在天气表> id,tamp_c,datetime列名的情况下。
查询是: -
select HOUR(transaction.time) as Hour ,
TRUNCATE(sum(transaction.total),2) as Total_Sales,
shops.gstIncludedSales as GST_Inc_Sales,
shops.gstFreeSales as GST_Free,weather.temp_c
from transaction,shops,weather
where transaction.shopid=shops.id and transaction.shopid=7
and transaction.transaction_date ='2015-05-25'
group by hour
ORDER BY hour DESC
的问题是,我想申请一个where
子句像time(datetime)='2015-05-25'
特定日期weather.datetime
表的分离,但它不工作。
你试过'日期(weather.datetime)='2015-05-25''什么? – vhu
对于其他任何一个表,似乎都没有天气的连接条件。你会得到什么结果,你期望什么? – PaulF
感谢您的回复保罗我想获取此表也SELECT * FROM'天气WHERE日期(datetime)='2015-05-25'和shop_id = 7 –