> how many teachers older than thirty?
> SELECT COUNT(*) FROM teacher WHERE teacher.Age > "thirty"
Not a bad idea. A good idea, maybe. Implementation needs some work.
> SELECT COUNT(*) FROM teacher WHERE teacher.Age > "thirty"
Not a bad idea. A good idea, maybe. Implementation needs some work.
how many teachers older than 30
teachers.filter(*.age > 30).len
Same length, but the second one has a degree of precision that the first lacks. (Though they might diverge somewhat as the complexity of queries grows, I suspect programming languages would do better as they have better facilities for symbolic manipulation.) Note also that the second example (and your SQL example) had to specify the table's name, while the natural language one did not—another mark against the natural language solution. teachers.Where(t => t.Age > 30).Count(); teachers[age > 30].count
(Because I'm working on something exactly like this right now) 27 42 44 > 30
0 1 1
If all you want is a count of teachers older than 30, you can simply sum up the resulting array, so: +/0 1 1 ⍝note: '/' is reduction, so +/ is sum reduction
2
If you want the indices, you can use 'where', which will produce an array of indices corresponding to 1s in its argument, so ⍸0 1 1
1 2
Indicates that '0 1 1' has 1s at indices 1 and 2. (We could also take the length of this array to get the count of teachers older than 30, although that would be a bit silly compared to just summing the original array.)We can then use these indices to index a different array:
ages←27 42 44
names←'anthony' 'barbara' 'bert'
names[1 2]
barbara bert
names[⍸ ages>30]
barbara bert
However, we don't even need to use 'where' in this case; the reduction operator (/) has a second use which lets us say: 0 1 1 / names
barbara bert
(ages > 30) / names
barbara bert
Good luck with your database, and hope this helps!