如何编写SQL语句以列出具有三个以上Makes
的所有Types
下面是数据表
Make Model Type
Chrysler Crossfire 2dr Sports
Ford Crown Victoria 4dr Sedan
Ford Crown Victoria LX 4dr Sedan
Ford Crown Victoria LX Sport 4dr Sedan
Honda CR-V LX SUV
Cadillac CTS VVT 4dr Sedan
Dodge Dakota Club Cab Truck
Dodge Dakota Regular Cab Truck
Cadillac Deville 4dr Sedan
Cadillac Deville DTS 4dr Sedan
Mitsubishi Diamante LS 4dr Sedan
Land Rover Discovery SE SUV
Dodge Durango SLT SUV
Mercedes-Benz E320 Wagon
Mercedes-Benz E320 4dr Sedan
Mercedes-Benz E500 Wagon
答案 0 :(得分:2)
您需要通过make &组对行进行分组键入,然后在您的SQL中使用having
。像这样的东西:
SELECT make FROM cars
GROUP BY make
HAVING COUNT(type) > 3
分组时, HAVING
与WHERE
类似
编辑:从GROUP BY
中删除了type
列
答案 1 :(得分:1)
使用以下查询
Group BY
方注意:通常,SELECT列表中的所有列名必须出现在GROUP BY子句中,除非name仅用于聚合函数
SQL GROUP BY子句与SELECT语句协作使用,以将相同的数据排列到组中。 GROUP BY子句在SELECT语句中跟随WHERE子句,并在ORDER BY子句之前。
在此link
中详细了解 div.smileyface {
width: 300px;
height: 300px;
position: relative;
border-radius: 150px;
-webkit-border-radius: 150px;
-moz-border-radius: 150px;
display: block;
background: #ffe632;
background: -webkit-gradient(linear, left top, left bottom, from(#fffe8d), to(#f6d23e));
background: -moz-linear-gradient(top, #fffe8d, #f6d23e);
box-shadow: inset 0px -14px 14px rgba(0, 0, 0, .3), 0px 2px 20px rgba(0, 0, 0, .6);
-webkit-box-shadow: inset 0px -14px 14px rgba(0, 0, 0, .3), 0px 2px 20px rgba(0, 0, 0, .6);
-moz-box-shadow: inset 0px -14px 14px rgba(0, 0, 0, .3), 0px 2px 20px rgba(0, 0, 0, .6);
}
p.eyes {
width: 50px;
height: 80px;
background: #222;
border-radius: 100px/160px;
-webkit-border-radius: 100px 160px;
-moz-border-radius: 100px/160px;
position: absolute;
top: 40px;
box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
-webkit-box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
-moz-box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
}
p.eyes.lefteye {
left: 75px;
}
p.eyes.righteye {
right: 75px;
}
div.smile {
width: 200px;
height: 70px;
border: 10px solid #222;
border-top: 0;
background: rgba(0,0,0,0);
-moz-border-radius: 0 0 120px 120px / 0 0 90px 90px;
-webkit-border-radius: 0 0 120px 120px 0 0 90px 90px;
border-radius: 0 0 120px 120px / 0 0 90px 90px;
position: absolute;
bottom: 50px;
left: 38px;
box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
-webkit-box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
-moz-box-shadow: 0 2px 0 rgba(255,255,255, 0.8);
}
div.corner {
width: 10px;
height: 30px;
background: #222;
border-radius: 100px/160px;
-webkit-border-radius: 100px 160px;
-moz-border-radius: 100px/160px;
position: absolute;
top: -12px;
-webkit-transform: rotate(65deg);
-moz-transform: rotate(65deg);
left: -12px;
}
div.corner.right {
left: 202px;
-webkit-transform: rotate(-65deg);
-moz-transform: rotate(-65deg);
}
答案 2 :(得分:0)
我认为你的意思是超过三种不同的类型。因此,请在COUNT DISTINCT
子句中使用HAVING
:
SELECT make
FROM cars
GROUP BY make
HAVING COUNT(DISTINCT type) > 3