The field exists only in dotable_a, not in dotable_b


select zn=2 as zn, substring_index(line,'-',1) as r,
sum(if(dove=1,1,0)) as line_a,
sum(if(dove=2,1,0)) as line_b,
count(substring_index(line,'-',1)) as q from (
select NULL as zn , NULL as wtf, line, 1 as dove from dotable_b
union all
select zn, zn=2 as wtf, line_mt, 2 as dove from dotable_a
) as tab
group by r
having q > 3
order by q desc

Output:


r		line_a	line_b	q	zn
DI5020317 	4	1	5	NULL
...
...

you’re not listening again

if you keep coming to this forum to get problems solved for you, you will have to follow along when we try to teach you sql

if you don’t want to learn sql, that’s okay too, but don’t keep asking us to solve your problems for you

i’m finished with this thread

good luck

If I write in the forum is because they want to learn.
But they may not understand the suggestions.
This is my big work, I’am sorry but I need only help in this forum.

This is the output required:

idDTES_ZONA	wtf
DM2N		0
DS1M		0
DM6M		0
DM6M		0
DI5M		0
DI5M		0
DI5M		0

I don’t explain so good.
You know my english is not good.
I don’t work in this things, I need your help.

your english is fine

your sql skills are terrible, and you do not seem to be able to learn

i am not helping you any more, sorry

I wrong with you?
I have asked you run this query

select zn, zn=2 as wtf from dotable_a

and show results in the post #22.
Apologize if I wrong with you…:sick: I’m sorry.

The point of that exercise was to make obvious why you don’t want to “select zn=2”. That you don’t attempt to interpret the results at all means you aren’t trying to learn.

I understand, this query:

select zn, zn=2 as wtf from dotable_a

is wrong… because wtf is 0…