خرید بک لینک

Vote count: 0

"F4111" is a table with detailed orders, where "SU" order types are output and "OU" order types are inputs. All "SU" orders are related to one specific "OU" order, so that the sum of all SU and OU orders should be zero. Their relationship is given by their ID. If SU orderID is 1000, then its OU related orderID is 1001. I have a SQL query that gives me some specific SU orders

SELECT F4111.orderID FROM F4111 F4111
WHERE F4111.orderDATE='2016/05/09' AND F4111.orderTYPE='SU' AND F4111.orderDESTINY='333333'

Now i need another query that gives me all the OU orders related to that specific SU orders, so i did this:

SELECT
F4111_1.orderID, 
F4111_1.orderTYPE, 
F4111_1.orderLINE, 
F4111_1.orderITEM,
F4111_1.orderQUANTITY
FROM F4111 F4111_1
WHERE
F4111_1.orderTYPE='OU' AND 
F4111_1.orderID in (SELECT DISTINCT (F4111.orderID+1) FROM F4111 F4111
WHERE F4111.orderDATE='2016/05/09' AND F4111.orderTYPE='SU' AND F4111.orderDESTINY='333333')

But this was very slow. It was faster to do N separate querys where N is the number of SU's given in the first query.

Any idea how to do this faster? Thanks in advance.

asked 3 mins ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 21 ارديبهشت 1395 ساعت: 21:31

صفحه بندی