#### Topic: Subquery in from or case?

Problem in request. It is necessary to deduce kol-in victories of each pair during the project.
Fought long, to begin and could not. Thought to do through CASE or to do the new table...
Operating time were in the plan

``````SELECT ID_para, SUM (ball) result;
case result when = then ' 1_win ' else ' lose ' end comment and
FROM sostav_sudi s JOIN vistuplenie v ON s.id_vistyplenia=v.id
WHERE dtvist = "2017-10-03"
GROUP BY ID_para``````

Whether At once there is a request it is possible to do case in case?
Intuitively understanding that the given construction will be big, besides it is necessary to invent further count _wins, becomes ripe a question, whether there is such possibility as in  languages, to fulfill a cycle with count in a variable. Since  in books and Google, clarified only presence if constructions and not necessary ..
Tables
Performance
Composition of judges

#### Re: Subquery in from or case?

Thought longer, solved so.

``````SELECT id_para, SUM (ball) as b1, id_vistyplenia, dtvist
FROM sostav_sudi s JOIN vistuplenie v ON s.id_vistyplenia=v.id
GROUP BY 3
HAVING SUM (ball)&gt;
ANY (SELECT SUM (ball)
FROM sostav_sudi s JOIN vistuplenie v ON s.id_vistyplenia=v.id WHERE dtvist = "2017-10-01"
GROUP BY id_vistyplenia)``````

Received each pair which has typed  ball in any competitive bottom.
Now an output problem, kol-in victories at each pair. But here an ill luck, at us here a drawn game on second of November.
I want to organize it a case. But something produces an error
[spoiler]

``````SELECT id_para, COUNT (b1)
,case WHEN b1=b1 WHEN "no wins" else "win" end q1
FROM (SELECT id_para, SUM (ball) as b1, id_vistyplenia, dtvist
FROM sostav_sudi s JOIN vistuplenie v ON s.id_vistyplenia=v.id
GROUP BY 3
HAVING SUM (ball)&gt;
ANY (SELECT SUM (ball)
FROM sostav_sudi s JOIN vistuplenie v ON s.id_vistyplenia=v.id WHERE dtvist = "2017-10-01"
GROUP BY id_vistyplenia)) as q1``````

[/spoiler]

#### Re: Subquery in from or case?

Whether

noobforsql wrote:

it is possible to do case in case?

It is possible. But what for?

#### Re: Subquery in from or case?

Akina, I decided to do by a subquery. Stuck here on an output kol-va (

#### Re: Subquery in from or case?

noobforsql , such impression that you ask us to be glad (or to sympathize)...
On one screenshots and the left unfinished requests, without made DDL and the full setting of the task, I think, anybody to help you especially and does not undertake.

#### Re: Subquery in from or case?

noobforsql;
It is possible to do enclosed Case expressions.

#### Re: Subquery in from or case?

It is impossible to do cycles, requests not on it.
On setting it agree with before. The orator.