it doesn't seem to fit into any scale!
I think you may be confusing being in a key versus in a scale.
You have the collection of tones
G A B♭ C D _ F♯ G. The tone
E is missing for a complete scale, assuming we are working with the gamut
ABCDEFG. We can't really speak about a complete scale, but we can talk about the key and tonality.
In terms of key you want to find a plausible tonic/dominant pair. Find a leading tone, that needs to be a half step relations ship. There are two
A B♭ and
G are the potential tonics. Is there a major chord or dominant seventh chord rooted a perfect fifth above either potential tonic, either a
D dominant seventh,
F major, or
F dominant seventh chord? Yes, you have a
D major chord in the left hand and it keeps going to
G minor. There is the dominant/tonic pair.
Does the melody confirm a key of
G minor, does it fit dominant/tonic harmony? Yes, the melody outlines the
D major chord and with it's continuation up to
C it fully outlines
D dominant seven. The other tones of the melody are
B♭. The melody is clearly in
That's sort of the "theoretical" way to describe analyzing the key, but in reality it's perfect clear to the ear that it's
In terms of scale you can't really say what scale is used, for two reasons: you don't play an
E - so you can't says whether it's harmonic minor or melodic minor, but more importantly the music is based more on chord tones than purely scalar ideas.
Below is the music with dominant chord tones highlighted pink, tonic tones green, and the stuff circled in red is just embellishment of chord tones...
Notice how you have about 85% chord tones and just a little bit of embellishing material? And the chord tone material coincides strongly with beats one on each bar.
I think you should consider things in terms of key and harmony rather than scale, at least for music like this example passage.