Comments - select based upon date...

10 years, 11 months ago Gary Vassalotti

I knew that... I stared at that problem for days... and still did not see that I missed the * in the select statement....

Duh....

Thanks for the help!

 
10 years, 11 months ago Gary Vassalotti

OK, the statement works only partialy.... for example, if I have:

SELECT SUM(AMOUNT), TRANSACT, transDate FROM ALESSAND WHERE transDATE > '2010-09-30';

I get correct results, however, if I add a qualifiers to the end, such as:

SELECT AMOUNT, TRANSACT, transDate FROM ALESSAND WHERE transDATE > '2010-09-30' AND TRANSACT = 'DEPOSIT' OR TRANSACT = 'WITHDRAW FUNDS';

Then I get all transactions that in those categories, for ALL dates, the transDate > part of the statement no longer works. This is true for ANY number of qualifers after the date qualifer.

What am I missing here??

 
10 years, 11 months ago Elena Stepanova

Hi,

It depends on what you are trying to get. Your query in its current form is equivalent of

SELECT AMOUNT, TRANSACT, transDate FROM ALESSAND 
WHERE 
( transDATE > '2010-09-30' AND TRANSACT = 'DEPOSIT' ) OR 
( TRANSACT = 'WITHDRAW FUNDS' );

That is, it will select all DEPOSIT transactions of date > 2010-09-30 and all WITHDRAW FUNDS transactions of any date. But I suppose it's not what you want. More likely, you are trying to select all transactions of date > 2010-09-30 which are either DEPOSIT or WITHDRAW FUNDS, in which case you're missing the brackets:

SELECT AMOUNT, TRANSACT, transDate 
FROM ALESSAND 
WHERE transDATE > '2010-09-30' AND ( TRANSACT = 'DEPOSIT' OR TRANSACT = 'WITHDRAW FUNDS' );
 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.