我试图选择多次满足某个条件的行以及满足该条件的次数.
例如,对于表格:
Animal ID NumKids PostCode
Cow 1202 5 1405
Cow 3492 6 4392
Chicken 4535 1 2394
Alpaca 2432 0 3453
Cow 2432 3 6253
Chicken 2342 5 4444
Run Code Online (Sandbox Code Playgroud)
选择每种类型超过4个孩子至少两次的动物以及发生这种情况的次数.
示例输出:
Animal Count
Cow 2
Run Code Online (Sandbox Code Playgroud)
我尝试过以下方面的事情:
SELECT animal
FROM Table
WHERE NumKids>4 AND COUNT((NumKids>4)>2);
Run Code Online (Sandbox Code Playgroud)
但是输出中存在明显的错误(仅输出动物名称而不是计数)并使用COUNT()作为条件.
如何实现一个以int开头的函数,并且每次从它中减去1(通过有限数量的可能性),其中一个(例如,5个)布尔值返回1.
理想情况下看起来如何:
function list1 list2 = num
where
num = 4
- (condition from var1 = true)
- (condition from var2 = true)
- (so on, so forth as long as needed)
Run Code Online (Sandbox Code Playgroud)
我尝试过类似的实现这些行:
num = startVal
- (list1conditional == desiredVal)
- (etc)
Run Code Online (Sandbox Code Playgroud)
但这是返回类型错误.
我已经声明了一个类型:
type Foo = (Char, Char, Char)
Run Code Online (Sandbox Code Playgroud)
并且希望能够解析一个 3 个字母的字符串“ABC”以生成一个输出 Foo,其中每个 ABC 作为类型的三个属性。
我目前的尝试是;
parseFoo :: String ? Maybe Foo
parseFoo str = f where
f (a, _, _) = str[0]
f (_, b, _) = str[1]
f (_, _, c) = str[2]
Run Code Online (Sandbox Code Playgroud)
这是返回错误:
Illegal operator ‘?’ in type ‘String ? Maybe Foo’
Use TypeOperators to allow operators in types
Run Code Online (Sandbox Code Playgroud)
我的问题是:
如何防止编译时出现此错误?
我是否在正确的轨道上?