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

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.

Related

joining 2 tables without duplicates [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
I am trying to join an old sql table with a new one but exclude the duplicate entries, this needs to be in a delphi program as well, and im a noob at that, any ideas?
These both keywords will make your data to combine and display in a single column.
Union - Removes the duplicate entries of the table
Union All - Includes the duplicate entries
It would be better if you provide an example with input and output, that would clarify your question the most.
you can use the union all operator instead of the union operator for joining two tables that not remove duplicates from the table.

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.

What is the specific use of Pivot table in SQL? [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
Im curious what is the distinct use of pivot table in database? I mean, how is it apply in real life.
Pivot query help us to generate an interactive table that quickly combines and compares large amounts of data. We can rotate its rows and columns to see different summaries of the source data, and we can display the details for areas of interest at a glance. It also help us to generate Multidimensional reporting.
for more information visit:
http://www.codeproject.com/Tips/500811/Simple-Way-To-Use-Pivot-In-SQL-Query
https://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx

MySQL Procedures for reporting total [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
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.

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