Jump to content
Fórum Script Brasil
  • 0

select dentro de selec

Guest --rogerio --


Guest --rogerio --

erro de query

ssql = "SELECT b.pn_bnc, b.model_bnc, Count(b.pn_bnc) AS Bounce, (SELECT COUNT(Bounce.laudo_new) FROM Bounce WHERE (Bounce.laudo_new = 'Sem defeito') AND (Bounce.bnc90d = b.bnc90d)) AS NTF FROM Bounce AS b WHERE(((b.bnc90d) = 'VERDADEIRO')) GROUP BY b.pn_bnc, b.model_bnc, b.bnc90d"

porque o campo criado NTF esta me retornando a soma total e não agrupada por pn_bnc?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

nota q sua subquery ta fazendo um select geral na sua tabela, e ela ta sem nenhum vinculo com a query principal (ou seja, o Group By da query princiapl não afeta a subquery).

pra resolver, você teria q fazer um Inner Join com a subquery (como se fosse uma view) q agrupasse de acordo com os campos pn_bnc e model_bnc (sendo q esses campos tb seriam os vinculos das duas views no Inner Join).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Create New...