0

I have a following query which gets data and shows as in Image below,enter image description here

SELECT 
TICKETS.TICKETID AS TICKET_NO,
RECEIPTS.DATENEW AS TICKET_DATE,
PAYMENTS.TOTAL AS MONEY,
CUSTOMERS.NAME AS CUSTOMER,
PAYMENTS.PAYMENT AS PAYMENT
FROM RECEIPTS
LEFT JOIN TICKETS ON RECEIPTS.ID = TICKETS.ID
LEFT JOIN PAYMENTS ON RECEIPTS.ID = PAYMENTS.RECEIPT
LEFT JOIN CUSTOMERS ON TICKETS.CUSTOMER = CUSTOMERS.ID
LEFT JOIN ADJUSTMENTS ON CUSTOMERS.ID = ADJUSTMENTS.CUSTOMER_ID
ORDER BY TICKETS.TICKETID

I have another table called ADJUSTMENTS having fields

ID CUSTOMER_ID ADJUSTMENT_AMOUNT ADJUSTMENT_REASON DATE

What I need is to pick up ADJUSTMENT_AMOUNT and DATE and place them exactly inside that table (shown in image) as an individual entry (ROW). I used UNION but what it did was to duplicate the entry and wasn't able to show that right under/within these rows but as a separate column. How can I do it?

This is the desired table I want to access from both tables enter image description here

4

1 回答 1

0

我会写在这里,所以它可以清楚。

aUNION会给你更多的行,aJOIN会给你更多的列。如果您只想为调整添加行。

如果您想显示调整行,您必须在查询中将它们的列命名为与您希望它们显示的名称相同SELECT ADJUSTMENT_AMOUNT AS MONEY

如果您希望他们在现有行上添加列,您必须考虑当您拥有 1 张票和多次调整时,您希望表格如何显示。显示多个调整当然会显示相同的工单表数据。

如果这不能回答您,请画一个小表格来显示您希望结果的样子。

于 2013-05-28T15:30:18.090 回答