1

Am having the following table structure,

--------------------------------------------------------
| id   |   po_bill_details_id   |   po_id   |   status |
--------------------------------------------------------
| 1    |   18                   |   6       |   1      |
| 2    |   16                   |   7       |   1      |
| 3    |   18                   |   7       |   1      |
--------------------------------------------------------

I need to select po_bill_details_id, which will be a common value for the given array of po_id. i.e. If i give [6,7] as input for po_id, i should only get 18 from po_bill_details_id and not 16. How can i query to MySQL for this logic?

4

4 回答 4

2

试试下面的。我在手机上,所以无法测试。根据数组中元素的数量,您可以更改计数。

SELECT bill_id FROM yourtable
WHERE PO_id IN (7,6) 
GROUP BY bill_d 
HAVING COUNT(DISTINCT po_id) = 2
于 2012-12-05T06:44:46.313 回答
1

你可以试试 ::

select 
po_bill_details_id

from table

where po_id in (/*your array*/)

group by po_bill_details_id having count(po_id)=(/*your array's length*/)
于 2012-12-05T06:35:34.600 回答
1
SELECT po_bill_details_id
FROM   <table>
WHERE  po_id IN ( 6, 7 )
HAVING COUNT(po_bill_details_id) > 1  
于 2012-12-05T06:36:51.177 回答
-1

你的意思是

select distinct po_bill_details_id from YOUR_TABLE where po_id=6 or po_id=7;
于 2012-12-05T06:33:09.263 回答