mysql-logic

Combining two conditional logic results into one case statement

I have written a query to Select sales values from a database and apply discounts if there were any used. The discounts are either a percentage or just a flat-value. My Query applies the discounts (first case statement) and then pulls the amount that was applied. It got me thinking if it was possible to get this done in one case state...

Is it possible to group rows by a day stored within a timestamp?

I'm not sure if this is even within the scope of MySQL to be honest or if some php is necessary here to parse the data. But if it is... some kind of stored procedure is likely necessary. I have a table that stores rows with a timestamp and an amount. My query is dynamic and will be searching based on a user-provided date range. I w...

WHERE clause causing table to omit LEFT JOIN rule

Hi, I am essentially attempting to modify this stored procedure. Modified stored procedure: CREATE PROCEDURE sp1(d1 date, d2 date, client INT(10)) declare d datetime; create TEMPORARY TABLE foo (d date NOT NULL, Amount INT(10) DEFAULT 0); set d = d1; while d <= d2 do insert into foo (d) values (d); ...

MYSQL: using des decrypt function with lower

Hey, I have encrypted user data in my database using des_encrypt, now when i specify a particular statement as below: SELECT LOWER( DES_DECRYPT( forename, 'ENCRYPT STRING' ) ) FROM Users All the results are NOT returned in lowercase, anybody know what i am doing wrong? or perhaps how another way to do it? p.s ENCRYPT STRING is a r...

Hierarchical MAX

Is there a way to get a row that has the MAX() when two fields are considered, giving one of them precedence. For example ID Column_A Column_B ---------------------------- 1 1 3 2 3 2 3 2 2 4 3 1 Would return ID Column_A Column_B --------...