Mysql sum as last row - mysql

Is it possible to have the SUM of all numaric fields in the last of a set of rows?
As of now, I'm using a very simple query such as:
SELECT
*,
SUM((UNIX_TIMESTAMP(end) - UNIX_TIMESTAMP(start))/3600)
FROM
times

in SQL you cant have a column that appears in only one row, likewise, you also cant have a row that doenst contain all the columns from the other rows.. So having a row that contains something unique is not possible. You can, however, add the calculated column to all rows in the dataset or do the calculation in the calling code after the data is returned.

I think what you are looking for is GROUP BY WITH ROLLUP you will find details on that in the MySQL manual.

Related

SSRS - How to create a sum (total) of an expression column?

After plenty of research, it seemd I can't find a well-explained solution to my problem. I'll join some screenshots of my Tablix, group rows, and group columns to help you to understand.
First of all, here's my tablix. It's linked to a SharePoint List.
The expressions are all like this :
=Count(Fields!ID.Value, "NameOfTheGroup")
It counts the number of elements that are filtered by one of the group chosen in the expression, and it works perfectly fine at this point.
Now, here's my groups :
They all contains filters tomanage the count precisely to the need.
What I want to do : In the last row, I want to display the sum of each column that is in a group row. But theses rows aren't datasets fields, they are just only expressions, and I can't find a way to create a proper total of each column. I heard of Running Value but the few solutions I found about it didn't work.
Thanks for the future help.
EDIT: Actually, the problem seems to be much more complex: any rows I create under my group rows are invisible : if I create a new row under the "Classification", outside the "Classification" row group, the expression I insert in the "CDI", "CDD", etc... columns stay blank. I tried with various expression or just values like "Hello World".

how to populate column from the content of other columns after a row is inserted in the same table in mysql

I have a table traffic with 7 columns, namely toll_id, date1, shift, car_single, car_return, car_local and car_total.
How could I populate first 5 columns manually, and then store a value in column car_total, which will be the sum of car_single and car_return?
Here is the image of my table:
Just to add a 3rd and 4th ways of achieving the desired outcome:
If you have at least MySQL v5.7.6, you can use a generated column as car_total.
Alternatively, you can choose not to store car_total at all, but calculate this value on the fly while querying the table.
Having a column to store the results of the calculation is good if you regularly have search based on that field because you can use indexes to speed up the searches. Calculating the results on the fly may be better, if you just need to display the result of the calculation, but there is no need to filter on it.
There are two ways to do this:
Add the logic in the application itself, so that it calculates total before inserting the record. (Recommended)
Write an after insert trigger (http://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html) which calculates the count when record is inserted.

SSRS Count Rows

I know variations of this question have been asked and I've read a lot of them but none of the solutions seem to work for me. I'm trying to get a row count or total count of only the results in one column. I can get a count using several different methods but only on the "dataset". As you can see from the image I want to count the number of rows returned for spcc_parcel. The counts I get now are wrong because I'm getting a total row count. Is it possible to just count the result rows?
Report Builder Screen Shot
This is how we count Total Records in our report
=CountRows("DataSetName")
From the question you posted, according to best of my understanding you are trying to count only those rows in which some specific column (let's say column 1) have some value,
So in order to do that you can use the following expression.
=Sum(IIf(IsNothing(Fields!Column1.Value) , 1, 0), "DatasetName")
What this expression will do is it will add 1 to the total if there exists some value in the Column name specified or otherwise add zero, after doing that with every row in the result set it will display the total in the corresponding field.
Let me know if it works.
Try this =Count("Dataset Name") or =Count("Tablix Name")

Different Number of Row counts?

I just created a table and ran a program which should add 170,256 rows.Then I checked the number of rows using PHP MyAdmin GUI. Below is the image.
According to the "Rows" column, I got only 162,230 rows! Then I ran the below query
SELECT COUNT(*) FROM `key_hash`
This generated the below result, which should be correct.
So my question is, how come the same thing display 2 different values? How should I know which is correct?
SELECT COUNT(*) FROM `key_hash`
provides you with exact row count.
What you see in summary (162,230) is just estimation (hence ~ sign)
Here is more detailed explaination
Why is the estimated rows count very different in phpmyadmin results?

How to get data from database but from the exact row?

I am using mysql. Now I want to write that query in which i will give mysql the row number then mysql will data from that column no only.
means..
if i have twenty rows in database but i want to get only 10th no of rows data? so how to write that kind query?
Create an INT field named "ID" that is set to "Auto Increment." This way each row will have a unique ID that you can use to select it. Details about how to do this are located here.
Add a column with the AUTO_INCREMENT flag on it, so that this columns contains the row number for all your rows. MySQL does not really have support for fetching a row by number, only by column value.