MySQL Procedures for reporting total [closed] - mysql

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Would anyone be able to help me with creating a procedure that reports the total amount paid in a specific month and specific year? Or how I would even go about creating this?
Thank you for any and all help.

I'm guessing you have a table that includes both a date column as well as an amount paid column. If that is the case, and you just want to sum the amount paid you can just use the SUM() function.
Try this:
SELECT SUM(totalAmountPaid) as totalForMonth
FROM tableName
WHERE MONTH(dateColumn) = monthYouWant AND YEAR(dateColumn) = yearYouWant
Here are date and time functions that may be useful.

Related

How to get a specific row of data for mysql with specification of company and agent [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
How to retrieve all the data pertaining to company name and agent from mysql? How to write the query statement?
Have you tried this?
SELECT *
FROM agent_info
WHERE policyCompany = 'Avia' and policyAgent = 'Ron';
I have to guess because you didn't tell us much about your tables, but this might work.
SELECT policyCompany,
GROUP_CONCAT(DISTINCT policyAgent ORDER BY policyAgent) agents
FROM mytable
GROUP BY policyCompany
You can read about GROUP_CONCAT() here.

How can I improve the query with grouping? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
How can I add a grouping for the "retirements" table by the "id_type" field and not just for everyone?
select name,
sum(retirements.price_per_product)
from retirements
join type_of_products top on retirements.id_product = top.id
where (date between '1998-11-01' and '1998-11-14')
group by name;
Do not resort to aggregate functions of each type? It's so rude.
There are two different ways to achieve this.
1. You may use a sub-query but it is expensive in terms of performance.
2. You may utilize the #temp table and join it in later part. A downside is it is
longer to code but performance is good especially in the long run.

Displaying latecomers of staffs [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to display the list of staffs who check into work late in a week. For example the staff checks in at 8.10 when the supposed check in time is at 8.00 AM. I am using datetime for the datetimein and datetimeout field. Can anyone suggest how should I do it?
Well, with no sample tables to work from, it's hard to give a clear answer. But I think what you're looking for is the TIME() function.
This should get you started in the right direction:
SELECT * FROM timeclock_records where TIME(datetimein) > "08:00:00";

MYSQL- Finding the total amount of playtime (from a column) from all lines and getting a sum [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
https://www.dropbox.com/s/7i5y1aggfjzl39c/photo.png
I want to get a total amount of playtime from the 38,000 users.
In addition, I want the sql query that will add the previous amount on the "playtime" column from each line and find a final sum.
Edit: Im really unsure If I was specific enough, I never ever got in a hard situation like this at expressing myself with English.
SELECT SUM(Playtime) FROM players;
That will give you the total amount of playtime from all users.
If you want to print the accumulated time on each row, try something like
SELECT #accumulated:=#accumulated+playtime as accum FROM players, (select #accumulated:=0) as accum

MYSQL avergae and MAX number [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I need to query a database table. structure:
id---bid ---veh_id---user_id
There is many data, all are veh_id related. User can place bid on veh_id as many as they want and on many veih_id.
I need to find the average bid on each veh_id and also the max bid receive for that veh_id. Can this be done in one SQL query. The optimal would have the difference betwenn the average and the max number. All group by veh_id.
I don't know where to start.
If I understood correctly:
SELECT MAX(bid), AVG(bid) FROM someTable GROUP BY veh_id