반응형
mysql/mariadb에서 ID가 같은 여러 행을 WHERE로 쿼리하는 방법
저는 꼼짝도 못하고 적절한 WHERE 쿼리를 수행하는 방법을 알아내려고 노력하고 있습니다.다음 표입니다.
post_id property_id property_value_id property_value_custom
77 2 3 NULL
79 1 1 NULL
79 2 2 NULL
79 2 3 NULL
79 4 NULL 111
80 3 4 NULL
게시물을 선택하고 싶습니다, WHEREproperty_value_id = 3
그리고.property_value_custom = "111"
.
결과는 post_id 79이어야 합니다.어떻게 질문하죠?
넌 할 수 있다.group by post_id
그리고 조건을 설정합니다.HAVING
조항:
select post_id
from tablename
group by post_id
having sum(property_value_id = 3) > 0
and sum(property_value_custom = 111) > 0
또는:
having max(property_value_id = 3) = 1
and max(property_value_custom = 111) = 1
언급URL : https://stackoverflow.com/questions/63567435/how-to-where-query-muliple-rows-with-the-same-id-as-one-in-mysql-mariadb
반응형
'programing' 카테고리의 다른 글
@미디어 미디어 쿼리 및 ASP.NET MVC 면도기 구문 충돌 (0) | 2023.09.24 |
---|---|
pyspark 데이터 프레임에서 문자열 유형의 열을 int 형식으로 변환하는 방법은 무엇입니까? (0) | 2023.09.24 |
각도에서 ng-click not fireing in Angular클릭 시 JS가 실행됩니다. (0) | 2023.09.24 |
Wordpress - Woocommerce remove "Added to Cart" 메시지 (0) | 2023.09.24 |
javascript에서 CSS 변수 접근 (0) | 2023.09.24 |