inblog logo
|
silver
    SQL문제풀기

    [SQL문제풀기] 특정 형질을 가지는 대장균 찾기

    silver's avatar
    silver
    May 22, 2025
    [SQL문제풀기] 특정 형질을 가지는 대장균 찾기
    Contents
    문제MYSQL

    문제

    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/301646

    MYSQL

    내가 작성한 오답

    select count(distinct id) COUNT from ecoli_data where GENOTYPE & 2 = 0 and (GENOTYPE & 1 > 0 or GENOTYPE & 3 >0 );
    : 막연하게 3번 형질이라고 해서 3과 비교를 했다. 이진수라 3번 형질은 2의 2에 위치하므로 4이다.
     
    notion image

    내가 작성한 정답

    select count(distinct id) COUNT from ecoli_data where not GENOTYPE & 2 = 0 and (GENOTYPE & 1 >0 or GENOTYPE & 4 >0 );

    내가 이전에 작성한 정답1

    SELECT COUNT(DISTINCT ID) COUNT FROM ECOLI_DATA ㄴWHERE (GENOTYPE & 2 = 0) AND ((GENOTYPE & 1 != 0) OR (GENOTYPE & 4 != 0));

    내가 이전에 작성한 정답2

    : 1과 4를 하나씩 비교하지 않고 한꺼번에 비교해 distinct를 사용하지 않았다.
    select count(id) count from ecoli_data where not (genotype & 2) = 2 and (genotype & 5) <> 0
    Share article

    silver

    RSS·Powered by Inblog