Jump to content
Fórum Script Brasil
  • 0

Query com datas


alphasil
 Share

Question

Olá pessoal

 

Poderiam ajudar-me numa query que não está a devolver-me os resultados esperados

SELECT i.`quantidade` - IFNULL(SUM(r.`quant`),0) AS total
FROM `item` AS i
LEFT JOIN `requisicoes` AS r ON (r.`id_item` = i.`id_itens`) WHERE i.`id_itens` = 8
AND (((r.`startDate` BETWEEN "2015-11-14 15:30:00" AND "2015-11-18 15:00:00" ) AND (r.`endDate` BETWEEN "2015-11-14 15:30:00" AND "2015-11-18 15:00:00")) OR (r.`startDate` <= "2015-11-14 15:30:00" AND r.`endDate` >= "2015-11-18 15:00:00"))

E está a dar-me 24 em 30 disponíveis e isso está errado porque tenho estas reservas

 

id_req  id_item  id_user  startDate            endDate               quant  created     
------  -------  -------  -------------------  -------------------  ------  ------------
    32        8        1  2015-11-16 12:00:00  2015-11-17 12:00:00       6  2015-11-11  
    57        8        1  2015-11-15 15:30:00  2015-11-20 15:00:00      24  2015-11-12  

Deveria dar 0 porque antes de

2015-11-16 12:00:00

não há nada mas depois há uma até ao dia

2015-11-17 12:00:00 

e como a minha pesquisa é entre 14 e 18....devia dar 0 e está a dar 24

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

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

Guest
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.

 Share



  • Forum Statistics

    • Total Topics
      149.9k
    • Total Posts
      646.8k
×
×
  • Create New...