Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 months ago.
Improve this question
I am developing an application that has database of mysql having orders and orderdetails table. order table having column orderStatus. My question is whether it is necessary to create another order log table if order status is 'closed' (that means completed orders) or just orderstatus column is enough.
From what you have described, I would assume a column is sufficient.
You might need another table if:
An order can have more than one status at the same time
You need to keep a history of when the order changed status
There might be other cases that would require another table, but you haven't described that any such condition applies in your case, as far as I can tell.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
1.insert into demotable1(list_of_all_columns) select * from demotable2 where some_condition;
2.insert into demotable1 select * from demotable2 where some_condition;
note: Table structure of demotable1 and demotable2 are same.
Which one of the above query statement is optimal?
"Optimal" -- They are the same.
MySQL will expand * into a list of columns as part of the parsing of the query. If you have a list of columns, it will verify that they are valid. So, no significant difference in performance. In general, performance of a query is dominated by fetching rows, not the details of what goes on inside the row.
"Desirable" --
On the other hand, * should not be used in most situations. What if you later added or deleted a column? Suddenly most queries with * in them would break. The main exception: You are simply dumping the data to see what is in the table.
Hence, option 3 is the only desirable version; it is unfortunate that it is not available.
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
I have a table named tblMitigation, which has several columns:
Headcode, Time, Origin, Destination, Mitigation, Next Service.
The Next Service column refers to another Headcode value in the same table. How can I use MySQL to look up the Mitigation column for that other service?
Thanks
Chris
You could JOIN the table to itself. Use a LEFT JOIN in case there is no Next Service as yet. The COALESCE will ensure the value of Next_Mitigation is something different in that case e.g. N/A
SELECT current.*, COALESCE(next.Mitigation, 'N/A') AS Next_Mitigation
FROM tblMitigation current
LEFT JOIN tblMitigation next ON next.Headcode = current.`Next Service`
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.
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.
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