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?
Related
I have edited the question to make the problem more simple and added the suggested changes in the coments, Thx a lot
I have a table matches with data and I need:
1- To get all the columns for matches before a date.
http://sqlfiddle.com/#!9/4ff02f/18
SELECT m1.* FROM matches AS m1 WHERE m1.date < '2019-02-23 00:00:00'
2- I need to add two columns with the “streak” for home and away teams in each match (or row). The “streak” for a team is the count of matches before the date of the current match in same competition, until the team lost a game (being home or away indistintly). The result would be kind of this:
results desired
I need to get all the info in only one query in MySql…and I am getting crazy with JOINS, SUBQUERIES,….They don´t get to do what I mean. Really appreciate some help
Thanks!
It sounds like you want to only populate specific fields for your streaks and that you want cumulative data. You may need to use fields that don't show (invisible, or just at the end) for "win/lose" and cumulative data to provide the count.
I don't have time to write a full solution right now, but this will be too long for a "comment" so bear with me:
Add columns for "Win" in home and away. Place a 1 or 0 accordingly.
Add columns for streak and conditionally include a cumulative count of Win IF the Win is 1. But if the win is Zero, set the cumulative back to Zero.
Example of CASE: https://www.w3schools.com/mysql/func_mysql_case.asp
Example of Cumulative: https://popsql.com/learn-sql/mysql/how-to-calculate-cumulative-sum-running-total-in-mysql
Once you have it written, you could likely combine these into a single function/field. But ... baby steps. Like the rest of us. :)
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".
I have a table with multiple fields that I am grabbing information from (8 to be specific) but within this query I need to group on one field (ID's) and sum two other fields separately (Units, MV). I can pull all the information together in 2-3 queries but I want to know if i can pull/put everything together in one query.
The correct result would be a query that groups the results on the ID field only, has both Units and MV summed separately but also have the other fields I need too. I can get part of the results in one query if I only have the grouped ID field and summed Units and MV fields but if I add any other fields then the results are incorrect. Any assistance would be appreciated.
I ended up messing around with using DISTINCT within the SQL portion of access and finally got the results. Thank you for all your help!
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.
I'm currently working on writing report generators. For one report I need to do a breakdown by a given characteristic (supplier, logging user, language, etc which for each row includes the name of the characteristic I'm interested in, the number of items that match that characterastic, and the percentage of total items this figure represents. The first two aren't a problem, the third is.
For example, to get a breakdown by language I'd be using a query like this.
SELECT lang_id,
COUNT(IF(open=TRUE,1,NULL)) AS lang_total
FROM table
GROUP BY lang_id;
This gives me the number of items per language.
I can get the total number of items in the table and store it in a variable simply enough with a plain count.
SELECT #totalOpen:=COUNT(*) FROM table WHERE open = TRUE;
Now I want to add a third column, which is the figure in lang_total divided by the value in #totalOpen multiplied by 100 (in other words, the percentage of all items that fit the criteria). Something along the lines of the following:
This is the bit I'm having trouble with, as because as far as I can tell you can't use aggregate columns in calculations.
SELECT lang_id,
COUNT(IF(open=true,1,NULL)) AS lang_total
(lang_total/#totalOpen)*100 as lang_percent
FROM table
GROUP BY lang_id;
I'm sure that there must be a way of doing this in MySQL, but I've not been able to track it down. Can anyone help out with this?
I read this question now for the first time. I know that probably it's too late to be useful for you but I would have solved in this way.
select lang_id,
sum(if(open= true,1,0)) as lang_total,
coalesce(sum(if(open= true,1,null)) / #r,0) as percentage
from table,(select #r:=count(*) from table where open = TRUE) as t
group by lang_id;