slick/slick — pull request #841 by imcharsi (2014-06-02 13:44:34+00:00)
Title: the With Clause(Common Table Expression)

Hi.
At first, my english is not good.

Use this feature like this:

```
val vTabA = TabA.rename("tabA")
val vTabB = TabB.rename("tabB")
vTabA.join(vTabB).on(...).
filter(...).map(...).
`with`(vTabA, TabA.filter(...)).
`with`(vTabB, TabB.filter(...).union(vTabB.filter(...)))
```

In some DBMSs, there are something restrictions like ORA-32042.
1:
Below query is not executed in some DBMSs.
```
vTabA.`with`(vTabA, TabA.union(vTabA.map(...).filter(...)..))
```
Instead, use like below.
```
vTabA.`with`(vTabA, TabA.union(vTabA.filter(...).map(...)..))
```

2:
In some DBMSs which have no support nested the With Clause, below query is not executed.
```
vTabA.
`with`(vTabA, TabA.filter(...)).
filter(...).map(...)
```
Instead, use like below.
```
vTabA.
filter(...).map(...).
`with`(vTabA, TabA.filter(...))
```
So, below query is not executed in some DBMSs, either.
```
vTabA.`with`(...).length
```
Instead, even though it is something verbose, please use like below.
```
vTabA.
groupBy(...).
map{case(g,t)=>t.map(t=>t.someCol).countDistinct}.
`with`(...)
```

There is a not yet solved problem.
1:
In some DBMSs, below query is not executed because .join creates nested sub-query.
```
withOne.
`with`(withOne,
TableA.unionAll(
withOne.join(TableA).on(_.num === _.num).map(_._2)))
```
I hope that in this case if it is possible, result sql text should not be nested sub-query.

Thanks.