Good Evening,
I have this query and i can't manage to fix it. It never finishes but it finishes on MSSQL 2000, i want to have it on MySQL. Any advice ?
SELECT T_Coll.Nom_REGION AS Region_Col,
T_Coll.Nom_STE AS Societe_Col,
T_Coll.Nom_ETS AS Ets_Col,
T_Coll.Nom_CDP AS CDP_Col,
T_Coll.ID_Coll,
T_Coll.NomColl AS NomColl,
T_Coll.Nom_Coll AS NOM,
T_Coll.Prenom_Coll AS Prenom,
T_Coll.Trig_Coll,
T_Coll.EXTERN,
T_DETAIL.AN,
T_DETAIL.Mois_Modif,
T_DETAIL.T_AFFAIRE_ID,
T_DETAIL.T_LOT_ID,
T_DETAIL.T_SOUS_LOT_ID,
T_Type.NomType,
T_DETAIL.AUTRE_LIBELLE,
T_DETAIL.JOUR01 + T_DETAIL.JOUR02 + T_DETAIL.JOUR03 + T_DETAIL.JOUR04 + T_DETAIL.JOUR05 + T_DETAIL.JOUR06 + T_DETAIL.JOUR07 + T_DETAIL.JOUR08 + T_DETAIL.JOUR09 + T_DETAIL.JOUR10 + T_DETAIL.JOUR11 + T_DETAIL.JOUR12 + T_DETAIL.JOUR13 + T_DETAIL.JOUR14 + T_DETAIL.JOUR15 + T_DETAIL.JOUR16 + T_DETAIL.JOUR17 + T_DETAIL.JOUR18 + T_DETAIL.JOUR19 + T_DETAIL.JOUR20 + T_DETAIL.JOUR21 + T_DETAIL.JOUR22 + T_DETAIL.JOUR23 + T_DETAIL.JOUR24 + T_DETAIL.JOUR25 + T_DETAIL.JOUR26 + T_DETAIL.JOUR27 + T_DETAIL.JOUR28 + T_DETAIL.JOUR29 + T_DETAIL.JOUR30 + T_DETAIL.JOUR31 AS Total_Jours,
T_DETAIL.JOUR01 + T_DETAIL.JOUR02 + T_DETAIL.JOUR03 + T_DETAIL.JOUR04 + T_DETAIL.JOUR05 + T_DETAIL.JOUR06 + T_DETAIL.JOUR07 + T_DETAIL.JOUR08 + T_DETAIL.JOUR09 + T_DETAIL.JOUR10 + T_DETAIL.JOUR11 + T_DETAIL.JOUR12 + T_DETAIL.JOUR13 + T_DETAIL.JOUR14 + T_DETAIL.JOUR15 + T_DETAIL.JOUR16 + T_DETAIL.JOUR17 + T_DETAIL.JOUR18 + T_DETAIL.JOUR19 + T_DETAIL.JOUR20 + T_DETAIL.JOUR21 + T_DETAIL.JOUR22 + T_DETAIL.JOUR23 + T_DETAIL.JOUR24 + T_DETAIL.JOUR25 + T_DETAIL.JOUR26 + T_DETAIL.JOUR27 + T_DETAIL.JOUR28 + T_DETAIL.JOUR29 + T_DETAIL.JOUR30 + T_DETAIL.JOUR31 + T_DETAIL.REGUL AS Total_Jours_et_Reg,
T_DETAIL.REGUL,
T_Cam.ID AS ID_Cram,
T_Cam.STATUT,
T_Cam.T_COLLABORATEUR_ID AS ID_Cram_Coll,
T_DETAIL.ID AS ID_Cram_Detail,
T_DETAIL.MOIS,
T_DETAIL.JOUR01,
T_DETAIL.JOUR02,
T_DETAIL.JOUR03,
T_DETAIL.JOUR04,
T_DETAIL.JOUR05,
T_DETAIL.JOUR06,
T_DETAIL.JOUR07,
T_DETAIL.JOUR08,
T_DETAIL.JOUR09,
T_DETAIL.JOUR10,
T_DETAIL.JOUR11,
T_DETAIL.JOUR12,
T_DETAIL.JOUR13,
T_DETAIL.JOUR14,
T_DETAIL.JOUR15,
T_DETAIL.JOUR16,
T_DETAIL.JOUR17,
T_DETAIL.JOUR18,
T_DETAIL.JOUR19,
T_DETAIL.JOUR20,
T_DETAIL.JOUR21,
T_DETAIL.JOUR22,
T_DETAIL.JOUR23,
T_DETAIL.JOUR24,
T_DETAIL.JOUR25,
T_DETAIL.JOUR26,
T_DETAIL.JOUR27,
T_DETAIL.JOUR28,
T_DETAIL.JOUR29,
T_DETAIL.JOUR30,
T_DETAIL.JOUR31,
T_Supr.Suppression,
T_Coll.TYPE
FROM T_Coll
INNER JOIN T_Cam ON T_Cam.T_COLLABORATEUR_ID = T_Coll.ID_Coll
INNER JOIN T_DETAIL ON T_DETAIL.T_Cam_ID = T_Cam.ID
INNER JOIN T_Type ON T_Type.TYPE = T_DETAIL.TYPE
LEFT OUTER JOIN T_Supr ON T_Supr.ID_Cram_Detail = T_DETAIL.ID
WHERE (T_Supr.Suppression IS NULL)
ORDER BY T_Coll.NomColl,
T_DETAIL.AN,
T_DETAIL.Mois_Modif,
T_DETAIL.T_AFFAIRE_ID,
T_DETAIL.T_LOT_ID,
T_DETAIL.T_SOUS_LOT_ID
I just can't manage to make this work under MySQL !
Thanks in advance !
All of the columns used in the joins, where clause and the order by should probably be indexed. You cannot expect any kind of decent performance in any database without indexes. There is nothing very complex about your query, so this is the most likely problem.
Do not return any columns you don't need. For instance why are you returning T_Supr.Suppression when the value will always be nulll based on your where clause?
In mysql you should look at the Explain Plan to see where the problem is with a slow query. In SQL Server look at the Execution PLan. You need to learn how to read these to effectively program in SQL.
Related
Lets say that I have data rows that look like this:
+----------------------------+
+ test_table +
+----+--------+--------------+
+ id + word + updated_word +
+----+--------+--------------+
+ 1 + g00gle + ggle +
+ 2 + bread0 + bread +
+ 3 + 0bject + bject +
+ 4 + d0d0 + dd +
+-------------+--------------+
What statement could I use to take out the zeroes in the word column, so that it looks like the updated_word column? I thought of using substring, but didn't know how to proceed after that.
try:
UPDATE test_table
SET word = REPLACE(word, '0', '');
replace the 2nd blank '' with anything you want to change with.
I have this query:
SELECT name, SUM(count_1 + count_2 + count_3 + count_4 + count_5 + count_6) AS Total
FROM my_table
Is there a way to add these values count_1 + count_2 + count_3 + count_4 + count_5 + count_6 and so on.. more efficiently? MySQL keeps crashing for me when I add huge numbers of fields.
Regardless of whether the db design is right or wrong if you use an aggregation function you should use group by
SELECT name, SUM(count_1 + count_2 + count_3 + count_4 + count_5 + count_6) AS Total
FROM my_table
GROUP BY name
select s_id, s_f_name, s_l_name, s_roll_no, s_class,
SUM(mid_1_english + mid_2_english)/2 as mid_english,
SUM(mid_1_mathematics + mid_2_mathematics)/2 as mid_mathematics,
semester_final_english,
semester_final_mathematics,
SUM((mid_1_english + mid_2_english)/2 + semester_final_english) as total_english,
SUM((mid_1_mathematics + mid_2_mathematics)/2 + semester_final_mathematics) as total_mathematics,
SUM((mid_1_mathematics + mid_2_mathematics)/2 + (mid_1_english + mid_2_english)/2 + semester_final_mathematics + semester_final_mathematics) as total
from elaborate_term_result_sheet
group by s_f_name, s_l_name
order by s_roll_no;
After running this query created, it does show the out put, but value is getting a bit fluctuated
mid_1_english + mid_2_english = mid_english
mid_1_mathematics + mid_2_mathematics = mid_mathematics
mid_english + semester_final_english = total_english
mid_mathematics + semester_final_mathematics = total_mathematics
total = total_english + total_mathematics
select s_id, s_f_name, s_l_name, s_roll_no, s_class,
SUM(mid_1_english + mid_2_english)/2 as mid_english,
SUM(mid_1_mathematics + mid_2_mathematics)/2 as mid_mathematics,
semester_final_english,
semester_final_mathematics,
SUM((mid_1_english + mid_2_english)/2 + semester_final_english) as total_english,
SUM((mid_1_mathematics + mid_2_mathematics)/2 + semester_final_mathematics) as total_mathematics,
SUM((mid_1_english + mid_2_english)/2 + semester_final_english + (mid_1_mathematics + mid_2_mathematics)/2 + semester_final_mathematics) as total from result_sheet_1 group by s_f_name, s_l_name order by s_roll_no;
the only change that gave the right output is
SUM((mid_1_english + mid_2_english)/2 + semester_final_english + (mid_1_mathematics + mid_2_mathematics)/2 + semester_final_mathematics) as total
the snapshot of the output of this query
I have a simple table in an HTML page. Nothing special.
The format is as follows:
+++++++++++++++++++++++++++++++++++++++++
+Col1 + Col2 + Col3 + Col4 + Col5 + Col6+
+++++++++++++++++++++++++++++++++++++++++
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
+++++++++++++++++++++++++++++++++++++++++
All the rows display text but I have the following problem:
If the contents in a row of Col6 are too big, then the row "expands" in 2 lines to fit the contents for that row and as a result the text in other column breaks in 2 lines.
E.g. if Col2 had the text: Some-text-in-here it becomes:
Some-text
in-here
And I don't want that.
How do we solve this issue with arrays so that each column does not get affect by the size of other columns this way?
You can use table-layout: fixed for table in combination with some explicit table width (e.g. width: 100%) to make table cell's widths independent from content width.
You can use white-space: nowrap to prevent line wrapping in an element.
I wanted to combine 11 columns of a form into single column.
here is my query
SELECT DormData.BuildingID,
BuildingDetails.BuildingName,
Contractors.Item,
ActionDetails.ActionType,
(DormData.Note1
+ DormData.Note2
+ DormData.Note3
+ DormData.Note4
+ DormData.Note5
+ DormData.Note6
+ DormData.Note7
+ DormData.Note8
+ DormData.Note9
+ DormData.Note10
+ DormData.Note11) AS Notes
FROM ActionDetails
INNER JOIN (Contractors
INNER JOIN (BuildingDetails
INNER JOIN DormData
ON BuildingDetails.BuildingID = DormData.BuildingID)
ON Contractors.ID = DormData.ItemID)
ON ActionDetails.ActionID = DormData.ActionID;
But not getting required result.
You need to replace the + with a &