Questions tagged [mysql-logic]
21 questions
3
votes
1 answer
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…

Derek Adair
- 21,846
- 31
- 97
- 134
2
votes
3 answers
Get row with largest negative number, or row with smallest number if there are no negative numbers
I'm trying to write a Snowflake SQL statement that does the following:
If there are negative numbers in column_A, return the row with the biggest negative number in column_A
If there are no negative numbers in column_A, return the row with the…

Milka
- 297
- 2
- 11
2
votes
2 answers
How to set the predefined value for the dropdown while we try to edit the data of a row?
I have created a list of employees with few fields which includes dropdown too. the problem is whenever i select edit option and redirected to the edit page the value in the dropdown is getting set to the first value in the database from which i am…

Akshay Vasu
- 445
- 1
- 12
- 33
2
votes
4 answers
WHERE clause causing table to omit LEFT JOIN rule
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);
…

Derek Adair
- 21,846
- 31
- 97
- 134
1
vote
0 answers
New login and user cannot login to database right away but works after random periods of time - Azure SQL Server
Command - 1 (Running on 'Master')
*CREATE LOGIN [login_Name] WITH PASSWORD=N'XXXXXX'*
Command - 2 (Running on 'Database_name')
*ALTER USER [User_name] WITH LOGIN= [login_name]
EXEC sp_addrolemember N'db_owner', N'Database_Name'*
When I try…

Amber Gupta
- 11
- 4
1
vote
1 answer
MySQL Query Logs Truncating Queries
I'm looking at the general log I've enabled in MySQl and it's working nicely.
However, queries appear to be truncated a little over 1000 characters.
What's the deal with that?

carrier
- 32,209
- 23
- 76
- 99
1
vote
1 answer
MYSQL: using des decrypt function with lower
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…

phpNutt
- 1,529
- 7
- 23
- 40
1
vote
1 answer
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…

Derek Adair
- 21,846
- 31
- 97
- 134
0
votes
0 answers
Complex Logic- Finding Renewals on Licenses
Need help in querying the below logic:
I have to calculate renewals. An org can order up to 5 licenses in total from us
License Table 2018
Year
Licenses
2018
A
2018
A
2018
B
2018
B
2018
C
2019
A
2019
A
2019
B
License Table…

Stan Smith
- 25
- 5
0
votes
1 answer
MySQL Insert if selected value > x
I am trying to write a MySQL insert that only inserts based on the result of a select query. I have found some information on using if-then-endIf logic in queries but haven't had any luck getting one to work. Then general idea that I am trying to…

Aaron Luman
- 635
- 1
- 10
- 29
0
votes
4 answers
How to create SQL based on complex rule?
I have 3 columns (id, date, amount) and trying to calculate 4th column (calculated_column).
How to create SQL query to do following:
The way that needs to be calculated is to look at ID (e.g. 1) and see all same IDs for that month (e.g. for first…

Joe
- 11,983
- 31
- 109
- 183
0
votes
1 answer
SQL locking of table in an inner join
Every day, I run a SQL statement to set an estimate of an aggregated value. This is a mysql server and the code looks like this:
UPDATE users
INNER JOIN (
SELECT user_id, COUNT(*) AS action_count
FROM action_log
GROUP BY user_id
) AS…

jamesatha
- 7,280
- 14
- 37
- 54
0
votes
2 answers
query from db for multiple rows and loop over it to insert for each record
my issue is
i want to query x rows from tbl_one and loop over the result and insert values into other table
select id as user_id, p_id from users where b_id = 0 // this will give me let's say 10 rows
and now i want to use each of the rows to…

Gunnrryy
- 350
- 1
- 5
- 17
0
votes
1 answer
Hive query not working as expected
id bigint from deserializer
created_at string from deserializer
source string from deserializer
favorited boolean …

rUCHIt
- 63
- 1
- 7
0
votes
1 answer
Finding top 10 trending tweets in Hive
I am finding top 10 trending tweets in hive on basis of retweet_count
ie The tweet which has highest retweet_count will be 1st and so-on....
Here is election Table details
id bigint from deserializer …

rUCHIt
- 63
- 1
- 7