Select multiple rows with the same value(s)

前端 未结 5 1102
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 10:17

I have a table, sort of like this:

ID  |  Chromosome | Locus | Symbol | Dominance |
===============================================
1   |      10     |   2           


        
5条回答
  •  庸人自扰
    2020-12-13 10:41

    You need to understand that when you include GROUP BY in your query you are telling SQL to combine rows. you will get one row per unique Locus value. The Having then filters those groups. Usually you specify an aggergate function in the select list like:

    --show how many of each Locus there is
    SELECT COUNT(*),Locus FROM Genes GROUP BY Locus
    
    --only show the groups that have more than one row in them
    SELECT COUNT(*),Locus FROM Genes GROUP BY Locus HAVING COUNT(*)>1
    
    --to just display all the rows for your condition, don't use GROUP BY or HAVING
    SELECT * FROM Genes WHERE Locus = '3' AND Chromosome = '10'
    

提交回复
热议问题