mysql - Trying to select all ID's from multiple tables and columns and order by the most matches -


Select all the IDs I have to do, which have the most matches and are listed in the order of the highest hit

East: I want to meet Sunday at 9 am and 11 am, 10am at 10am and at 11am and on Tuesday at 9am and then want to sort them by most hits < / P>

  • C hit
  • A4 hit
  • B2 First, let's ask a question to massage the data in a few simple ways:
  •   Selection ID, 0 AO Dow, 8 hours as, '8 AM' All Selection IDs from the Vivar Sangh, 0 AR Dow, as 9 Hours, All Selection IDs from Sunday Union, 0 AS Dow, 10 Hours as '9 AM', hit as `10 AM` on Sundays All select IDs from the unit, 0 AS Dow, 11 hours as on 11th Sunday, all selected units, 1 AS Dow, 8 hours as 8 hrs, Mandai Union All Selection ID, 1 AS Dow , As 9 hours, 9 AM, as all the selection IDs from Monday Union, 1 AS Dr , All select IDs from Monday Union like '10 AM', all selection IDs from Monday Union, 1 AS Dow, 11 HR, `11 AM 'as all selection IDs from Monday Union, 2 AS Dow, 8 Hours, All selection IDs from Tuesday, April 8, 'AS' hit Tuesday, 2 AR Dow, 9 hours as on 9 o'clock, as on Tuesday Union Select All ID, 2 AR Dow, 10 Hours, `10 AM ' From Tuesday, all the selection IDs, 2 AS Dow, as 11 hours, from Tuesday as `11 o'clock 'to Tuesday You can choose from this (derived) table:  
      SELECT ID, SUM (hit) form In FROM (- above the query, either as a view or derived table - or permanently converted) hit table WHERE (Dow = 0 and HR IN (9, 11)) or (Dow = 1 and hour (10   

    Note WHERE

    The simplicity of the code> section is if you have control over your schema. I stored data the way in this format, I recommend the change becomes permanent. This will make your life easier by lot if you can not do that, then I suggest at least one such scene that adds all the tables in this fashion, so that you can easily ask them .


    Can you do it with your existing schema? Sure, and it may seem "short" or "simple", but it's not as beautiful if you are dynamically creating these questions:

      SELECT ID, SUM (hit) ) All select IDs from `10 AM` + 11 AM 'from all selected IDs selected from AS (Selection ID,` 9 AM` + 11 AM S & E Union) are hit by TAUDA by `9 AM on Monday. ) SUM (Hit) DESC by S Group    

  • Comments

    Popular posts from this blog

    excel vba - How to delete Solver(SOLVER.XLAM) code -

    github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

    ios - Replace text in UITextView run slowly -