我正在编写一个SQL查询,它将返回客户账单付款的数据。
我们将这些付款分为两个不同的表格,一个是“票据”,另一个是“收据”。当我的查询数据按升序显示“收据数据”(来自收据表)。我还有两个日期列显示在结果集中,即“账单月”和“截止日期”(来自账单表)。当我尝试在任何这些提到的列上应用order时,它显示错误的数据。请帮忙。
我的查询附于下方。谢谢。
select distinct
bil.bill_id as Bill#, --(bill), this table has bill month and due date column
rec.receiptid as IDs, --(receipts),this table has receipt payment date,amount
sp.spaceno as spaceno,-- (space), this table has property names
lo.description as locaiton,-- (location),this table has details of property
one.name as owner_name,-- (owner), this table has owners information
bt.billtype as Particular,--(billtype),where bill types are saved
rec.rdate as Date,-- this column of receipt table showing wrong date data
dc.dr as opening,-- (DCnotes), this table has total payable amount column
rec.amount as dr,-- this column tells the paid amount
bil.amount as cr,-- this columen tell the payable amount
bil.balamount as balance,-- this column tells the net total of dr-cr columns
bil.billmonth as BillMonth,-- bill month column from bill table
bil.duedate as DueDate -- bill due date column from bill table
from
bills bil
inner join
Owners one on bil.ownerid = one.ownerid
inner join
Receipts rec on bil.spaceid = rec.propertyid
inner join
DCnotes dc on bil.spaceid = dc.property
inner join
BillTypes bt on bil.billtypeid = bt.billtypeid
inner join
Spaces sp on bil.spaceid = sp.spaceid
inner join
Locations lo on sp.locationid = lo.locationid
where
bil.siteid = '15'
这是SQL查询结果的图像:
这是报告中所需数据的图像:
请检查所需数据和SQL查询结果的附加图像