2012-09-22 125 views
0

我有三個表。簡單的MySQL查詢

CLIENTS 
JOBS 
INVOICES 

我需要看到每一行發票表某某白天分組的日期之間,示出相關JOBID和哪個客戶端(通過名稱)連接。發票只通過JOB ID連接到客戶端。

這是否有意義?

SELECT 
    j.ID As JobID, 
    CONCAT(c.FIRSTNAME, ' ', c.LASTNAME) As ClientName, 
    c.ID As ClientID 
    i.DATE 
    i.LENSES 
    i.FRAMES 
    i.TAXABLEGOODS 
    i.DISCOUNT 
    i.PAYMENT 
    i.PAYMENTTYPE 
    i.PREVIOUSBALANCE 
FROM 
    JOBS j, 
    CLIENTS c, 
    INVOICES i, 
WHERE 
    i.JOBID = j.ID 
    j.CLIENTID = c.ID 
GROUP BY DATE 

有什麼建議?

回答

0

使用方法如下:

WHERE your_date between first_date AND last_date GROUP BY YEAR(your_date), MONTH(your_date), DAY(your_date);