Tuesday, 15 January 2013

mysql - Is there any way I can change this SQL so the terms are defined only once? -


Is there any way I can change this SQL so that words are only defined once? . Selection amount (score) score, by selecting the title (selection score, titled 3, score, 'a railway staff'), Union Select All 2 score, 'one railway' Choose the word Unius All 2 score, the word 'railway worker' word union, all selected 1 point, 'one' word unius all select 1 point, word 'railway' word of union all, 1 score, 'employee' words) Table title (eg 'Union All Select Score * 1.1 points, by title ( Selection 3 score, the word 'a railway worker' word union, all selected 2 score, 'one railway', the word 'one railway', all 2 selected, 'railway staff' word union, all select 1 point, 'one' word unius all select 1 The words, 'railway', the word 'railway', all select 1 score, 'employee' words) are included in the words summary ('%', the word '<', the word

Note: I recommend that you put the prices in your table. Rsn lesson in sticking to them is probably not ideal. But I submit the question that he's equally well it will work as hard-coded derived table with the actual table.

Here's a way:

  Sequence sum (score * multiplier) score, 3 with title (selection 3 score, 'one railway worker' word union, all select 2 Select the 'one railway' union 2, the 'railway worker' union select all, select one 'union', select one of all, select 'railway unius all of 1, employee') (select 'title', ' The selection of 1 multiplier union all, 'Summary', 1.1) Include the table name in the X INNER case. X 'WHERE' when titled 'Then' Title 'Summary' Summary and Contact Order ('%', terms.term, '%');   

And here's another way that's basically the same, but shuffle around a bit:

  SELECT Select the sum (terms.score * T. Multiplayer) score, titled (3, select 'a railway worker'), Unione all select 2, 'one railway' union selection 2, 'railway staff' union all select 1 , 'One Union All Select 1', 'Railway Union All Select 1', 'Employee') The word Inner Join (selection title, Case X. which was then titled 'title' when 'Summary') The end date comparison, from the X.Multiplier to the tabular name (selection 'title', which is the selection of 1 multiplier UNION allocation 'Summary', 1.1) X) Contact on 'T' Comterine ('%', rule. MRM, '%' ) Order by Title DESC Group;   

And finally, another way:

  from SELECT * (SELECT sum (terms.score * (case when Title like 'T' ('%', Terms.term, '%') again 1 ELSE 0 END + case when T-type like COMATAT ('%', 'word', '%') then 1.1 ELSE 0 END)) Join the title, TALNAMAN T TRASS by the title (3, select the word 'A railway worker') Union All Select 2, 'A Railway' Association Selection 2, 'Railway Staff' Union All Select 1, A 'Union All Select 1,' Railway Union All Select 1 ',' Employee ') The word gru Score by Title Order by DESC) Z Zedcore Core & gt; 0;   

In addition, if there is something in MySQL that is similar to Cross Epiply , then it cross JOIN Is an external reference, so it becomes somewhat easier (i.e., the first query can be completely lost by the CASE statement).

No comments:

Post a Comment