original table
I condensed it with
SELECT type_value, number FROM parts_usage GROUP BY number, type_value
to get result of code
Then i need to add the columns to get 15
When I try to add them it adds all the rows before condensing them down.
I would like you know how I can sum up all values from a single table column based on a specific constraint. What I mean is this, imagine a table called payments, the payments table has three columns; ID, type of payment and amount. ID is not a primary key so it can duplicate. So let's say there are four entries under one particular ID and I want to get the total for amount for that ID. How can I do it? Thought a while loop would work but tried everything I could think of and it didn't. Please help! Final school project
If you are using mysql you can use the sum function as follows:
SELECT SUM(t1.ID) FROM db1.tblmoney AS t1 WHERE t1.ID = '1';
This will select the sum total of column "ID" in all rows within db1.tblmoney with the ID of 1. If on the other hand you are trying to get a count of the rows with that ID you can use this:
SELECT COUNT(t1.*) FROM db1.tblmoney AS t1 WHERE t1.ID = '1';
The different in these two statements is SUM with get the added values of all ID
So if you have 2 rows of id ='1' you will get 2 if you have two rows of id = '2' you will get 4
Whereas with Count() it will count the number of rows matching your select: 2 rows of id ='1' you will get 2 if you have two rows of id = '2' you will get 2.
I'm trying to select multiple Invoiceno from my database table with one mysql query but i get an empty records
here what i've tried
$invoiceNo1="'".implode("','", $invoiceNo)."'";
$queryInv="SELECT invoice_no,invoice_date,invoicetype FROM invoice_lineitem where invoice_no in ($invoiceNo1)";
but i get an empty array
I would like to search and count unique values in a column/fieldname of a MySQL Result Set.
In other words, when some lines of one table are stored in a mysql resultset I want to know which values are stored in a specific column/fieldname of all stored lines.
SELECT COUNT(DISTINCT columnname) AS Total FROM yourtable
SELECT webcal_entry.cal_id, webcal_entry.cal_name , webcal_entry.cal_priority,
webcal_entry.cal_date , webcal_entry.cal_time , webcal_entry_user.cal_status,
webcal_entry.cal_create_by , webcal_entry.cal_access, webcal_entry.cal_duration ,
webcal_entry.cal_description , webcal_entry_user.cal_category
FROM webcal_entry, webcal_entry_user
WHERE webcal_entry.cal_date BETWEEN '20090601' AND '20090631'
When I execute that query php throws back:
mysql_query(): unable to save result set
MySQL client ran out of memory
When I limit the results I see that it is pulling some 2.8 million results back. This table has 7,241 rows.
I realize I could use LIKE, but I really don't want to go that route.
Thanks for any help!
You are joining the webcal_entry and webcal_entry_user tables in your FROM clause but you do not have any JOIN ON or WHERE conditions constraining which rows from webcal_entry_user to return. The result will be the cartesian product of the two tables, which basically means you'll get back each webcal_entry row that has a valid cal_date, multiplied by the number of rows in the webcal_entry_user table.
In other words, if you webcal_entry_user has 400 rows you'll get back 400*7241 = 2.8 million rows! Yikes!
You're doing a cartesian join. Basically, for each row in the first table you're joining against all the rows in the second. If the first table has 4 rows and the second 10 the result set will have 40 (4x10)
You need to add the key you're joining on that exists in both tables to the WHERE clause. Something like:
AND webcal_entry.user_id = webcal_entry_user.user_id