这是我使用的SQL语句:
SELECT a.Customer_ID, a.Customer_Name,c.Service_ID
, c.Service_Name,f.Service_Type,c.Service_Price
, e.Bill_ID, e.Bill_Day, e.Due_Bill_Day
FROM customers a,customer_service b,services c
, billing_services d, billing e, services_type f
WHERE a.Customer_ID = b.Customer_ID AND b.Service_ID = c.Service_ID
AND c.Service_ID = d.Service_ID AND d.Bill_ID = e.Bill_ID
AND c.Service_Type = f.ID
我对SQL语句的问题很少。 我可以知道上层语句与使用连接相同吗? (性能与特点?) 2.我想将结果显示一次,如果重复,差异结果显示两次,用于账单对账单。
谢谢。
答案 0 :(得分:0)
SELECT max(a.Customer_ID), max(a.Customer_Name),max(c.Service_ID)
, max(c.Service_Name),max(f.Service_Type),max(c.Service_Price)
, max(e.Bill_ID), max(e.Bill_Day), max(e.Due_Bill_Day)
FROM customers a inner join customer_service b on(a.Customer_ID = b.Customer_ID) inner join services c on (b.Service_ID = c.Service_ID)
inner join billing_services d on(c.Service_ID = d.Service_ID) inner join billing e on(d.Bill_ID = e.Bill_ID ) inner join services_type f on( c.Service_Type = f.ID)
group by a.Customer_ID, a.Customer_Name,c.Service_ID
, c.Service_Name,f.Service_Type,c.Service_Price
, e.Bill_ID, e.Bill_Day, e.Due_Bill_Day
试试此代码