MySQL states
If you set a column to the value it currently has, MySQL notices this and does not update it.
So for example I have 20 columns and i am about to update them all but 10 of them will still have the same value. Will the performance or speed behaves the same way like you are updating just 10 columns? Or is it the other way around?
In your example, in the first case there will be 20 checks and 10 updates.
For 10 columns, there will be 10 checks and 10 updates.
So you "win" 10 checks in MySQL-side performance.
Related
I have been tasked at work to identify repeat callers in MySQL. I have a datetime for when the interaction begins, a callers phone number as well as a queue that it entered. I am looking to add a casewhen statement that will add a column to my results with either a 1, if the same combination of phone number and queue is recorded in the last 14 days, and a 0 if it wasnt.
Notable things about the image:
Row 6 is a 0 due to the fact the queues on row 4 and 6 do not match. Row 8 then has a 1 because rows 4 and 8 match.
Due to the phone number and queues matching on rows 3 and 7, row 7 has been given a 1. There is then another repeat call on row 10. Due to a 1 already being in one of the duplicates in its 14 day lookback, I want this to return a 0.
Any help on this would be greatly appreciated. Really not sure where to even start.
I'm not sure if SSRS is dumb, or I am (I'm leaning towards both).
I have a dataset that (as a result of joins etc) has some columns with the same values duplicated across every row (fairly standard database stuff):
rid cnt bid flg1 flg2
-------------------------------
4 2882 1 17 3
5 2784 1 17 3
6 1293 1 17 3
18 9288 2 4 9
20 762 2 4 9
Reporting based on cnt is straightforward enough. I can also make a tablix that shows the following:
bid flg1 flg2
------------------
1 17 3
2 4 9
(Where the tablix is grouped by Fields!bid.Value and the columns are just Fields!flg1.Value and Fields!flg2.Value respectively.)
What I can't figure out is how to display the sum of these values -- specifically I want to show that the sum of flg1 is 21 and the sum of flg2 is 12 -- not the sum of every row in the dataset (counting each value more than once).
(Note that I'm not looking for a sum of distinct values, as they may not be unique. I want a sum of one value from each bid group, because it's from a table join so they will always have the same value.)
If possible, I'd also like to be able to do a similar calculation at the top level of the report (not in any tablix); although I'd settle for hiding the detail row if that's the only way.
Obviously, Sum(Fields!flg1.Value) isn't the answer, as this either returns 51 (if on the first row inside the group) or 59 (if outside it).
I also tried Sum(Fields!flg1.Value, "bid") but this wasn't considered a valid scope.
I also tried Sum(First(Fields!flg1.Value, "bid")) but apparently you're not allowed to sum first values for some weird reason (and may have had the same scope problem anyway).
Using Sum(Max(Fields!flg1.Value, "bid")) does work, but feels wrong. Is there a better way to do this?
(Related: is there a good way to save the result of that calculation so that I can later also show a Sum of those totals without an even hairier expression?)
There are two basic ways to do this.
Do what you have already done (Sum(Max(Fields!flg1.Value, "bid")))
Sum the rendered values. To do this check the name of the cell containing the data you want (check it's properties) and then use something like =SUM(ReportItems!flg1.Value) where flg1 is the name of the textbox, which is not necessarily always the same name as the field.
ok, i'm not sure if i can explain this right.
Lets say i have a table with three columns (id, price, maxcombo)
maybe there's like 5 rows in this table with random numbers for price. 2. id is just incremental unique key)
maxcombo specified if that price can be in a combination of up to whatever number it is.
If x was 3, i would need to find the combination that has the maximum value of the sum 1-3 columns.
So say the table had:
1 - 100 - 1
2 - 50 - 3
3 - 10 - 3
4 - 15 - 3
5 - 20 - 2
the correct answer with be just row id 1.
since 100 alone (and can only be alone based on the maxcombo number)
is greater than say 50 + 20 + 15 or 20 + 15 or 10 + 20 etc.
Does that make sense?
I mean i could just calculate all the diff combinations and see which has the largest value, but i would imagine that would take a very long time if the table was larger than 5 rows.
Was wondering any math genius or super dev out there had some advice or creative way to figure this out in a more efficient manner.
Thanks ahead of time!
I built this solution to achieve the desired query. However, it hasn't been tested in terms of efficiency.
Following the example of colums 1-3:
SELECT max(a+b+c) FROM sample_table WHERE a < 3;
EDIT:
Looking at:
The correct answer will be just row id 1
...I considered maybe I misunderstood your question, and you want the query just obtain the rowid. So, I made this other one:
SELECT a FROM sum_combo WHERE a+b+c=(
SELECT max(a+b+c) FROM sum_combo WHERE a > 3
);
Which would for sure take too long in larger tables than just 5 rows.
I would like help with sql query code to push the consequent data in a specific column down by a row.
For example in a random table like the following,
x column y column
6 6
9 4
89 30
34 15
the results should be "pushed" down a row, meaning
x column y column
6 null or 0 (preferably)
9 6
89 4
34 30
SQL tables have no inherent concept of ordering. Hence, the concept of "next row" does not make sense.
Your example has no column that specifies the order for the rows. There is no definition of next. So, what you want to do cannot be done.
I am not aware of a simple way to do this with the way you are showing the table being formatted. If your perhaps added two consecutively numbered integer fields that provide row number and row number + 1 values, you could join the table to itself and get that information.
After taking a backup of you table:
Make a PHP function that will:
- Load all values of Y into an array
- Set Y = 0 (MYSQL UPDATE)
- load the values back from PHP array to MYSQL
say if the table trap has column 'id' and rows contents as
7
8
9
10
11
12
13
14
SELECT id FROM trap
WHERE id<10 and id>12
this doesn't give any output
but if
SELECT id FROM trap
WHERE id>7 and id<14
give me the required output i.e.,
8
9
10
11
12
13
The problem is that you're using the AND operator where you should be using OR.
SELECT id FROM trap WHERE id<10 OR id>12
Obviously id cannot be both 10 AND 12 at the same time, one box can only hold one value.
Alternatively you can write the statement as:
SELECT id FROM trap WHERE NOT(id BETWEEN 10 AND 12)
The reason that SELECT id FROM trap WHERE id>7 and id<14 does work is that it is possible for a value to be BETWEEN 8 AND 13 (inclusive) at the same time.
However no way can a value ever the smaller than 10 and larger than 12 at the same time.
So if the conditions are mutually exclusive you must use OR, if the conditions do not exclude one and other then you must use AND.
You can wrap a test inside a NOT() to reverse the test, this is because AND and OR are exact opposites.
I think you're mistaken, or you've phrased the question wrong.
It's impossible for id < 10 and id > 12 to be true at the same time. That's why you aren't getting any results for your first query.
What you're looking for is:
SELECT id FROM trap WHERE id<10 OR id>12