Sorting mysql resultset based on date

Sorting mysql resultset based on date

Hi,
I got 2 columns, “firstName” and “myDate”
“myDate” stores date in this format: “2020-11-29” (YYYY-mm-dd format)
Its a varchar column
SEMrush

There could be multiple records for each “firstName”, the date will differ.
example:
(‘jeet’, ‘2020-05-30’),
(‘jeet’, ‘2020-05-31’),
(‘Lucky’, ‘2020-05-31’),
(‘Lucky’, ‘2020-06-01’),
etc.

I am trying to select all “firstName”, but only 1 record for each name, the one with the smallest date.

select * from table order by myDate asc group by firstName

Problem is “myDate” is a varchar column, and I am not sure if results will be sorted correctly all the time.
So I was hoping to convert myDate input to a numerical format like unix timestamp, and then sort it.
How can I do this in the query?
Thanks

 

sorting – How to sort alphabetically based on a particular column in notepad++?

I was unsure how to word the inquiry. I have a huge swath of a few thousand entries i’d like to sort alphabetically but using the built-in notepad++ sorts numbers first and in my case, i need a certain portion ignored. Showing is the only way i know how to explain this.

Here is some example data

000500001010a900       1baf3214cb4b7a7b0aeb1b287d2e9d1a       Super Mario Kart                    
000500001010ab00       4e2a55f304b20e1af742bfbc710f5f40       Batman Arkham City: Armored Edition 
000500001010ac00       7092878593502e59e62b3b75de3de8b4       BEN 10 OMNIVERSE™                   
000500001010ad00       34a8f7d901a8e0358377bff9ae13c779       Darksiders II                       
000500001010ae00       b685d174175996dfcef21b6a14c601b1       JUST DANCE 4                        
000500001010af00       76e7ad38eed475ffbd7b416f49f34fe9       Marvel Avengers™: Battle for Earth  

as you can see, its sorting based off the numbers, I’d like to sort based off the title. Easy enough if i omitted all the rest, but I need to keep the title in the same row as the title id and key. Therein lies my issue.

Algorithm for rule-based sorting?

I am trying to plant a garden. Certain plants are good for some plants and bad for others, and I am trying to find the best order of plants: most adjacent friends and no adjacent foes, as defined in this table:

Num Vegetable   Friends       Foes
1   Watermelon  7,4,3          8,6
2   Tomatoes    9,8,6,5,1      7
3   Sunflowers  7,6,11  
4   Zucchini    9,7,3   
5   Eggplant    9,6,2          7,10
6   Cucumbers   9,7,3          8,1
7   Corn        8,6,4,3,1      5,2
8   Cantelloupe 7,4,3          6,1
9   Bell peppers6,5,11,10,2 
10  Swiss chard 2              5
11  Rhubarb     9,3 

Assuming I have one of each plant and they are being planted in a row, how do I sort them (most efficiently) so that I will get the most adjacent friends and no adjacent enemies? There are tools online, but I am trying to understand the thought process and the implementation. Java is a language I know, so that would be the most helpful out of any language, but the concepts are the main point for me.

Sorting sprite drawing orders for a descending 2D game with floors and bridges

I'm working on a custom 2D engine for a game.
I'm having trouble finding a working system for sorting by order of drawing sprites for this specific game.

Game description:

  • 2D
  • Top-down perspective
  • Many floors
  • Bridges


More details for clarity:

  • Characters (player characters, enemies, NPCs) can be positioned and move on any floor and move between floors.
  • Objects (crates, etc.) can be positioned on any floor. (Not on the stairs.)
  • The floors are crossed using stairs.
    The staircase is a "ramp" connecting 2 floors.
    The staircase can connect 2 floors which can be separated from any number of floors.
  • Characters and objects cannot be positioned / moved "behind" the rear-facing walls and behind the objects.
  • Characters can be positioned / move behind and pass between other characters.
  • Characters and objects can be positioned / moved both on and under a bridge.

The entities that need their sorted sprites are characters, objects and bridges.
The visuals (tiles) that make up the rest of the game level, are rendered first (under everything else) in a single pass, and don't need any sort of sorting.

What I have tried so far:

V0. Sort by Y
Obviously, this does not work because it cannot resolve the verticality (floors).

V1. Sort characters into lists by current character level, then sort each list by character stream Y
Than drawing for example.
Floor 0 List of sorted characters
1st floor bridges
Floor 1 List of sorted characters

The problem with this approach is that the floor must have a hard edge.
Each character is at a point on one and only one floor.
When two characters are close enough to each other on the Y axis to overlap and each is on a different floor, this happens:

V2. Sort characters and bridges using "painter's algorithm" (average distance to camera from vertices of 3D rectangles)
Even if the graphics engine is 2D, I defined each character and bridge as a rectangle positioned in 3D and defined a virtual camera (point of view) with a 3D position.
Than the calculated average 3D position of each entity and its distance from the camera. What sorted by distance.

The problem with this approach is one of the problems of the Painter algorithm: the distance to the camera is calculated from the position of the center point of the rectangle.
The larger the rectangle, the more imprecise the calculation.
If the rectangle is large enough, it will begin to erroneously overlap the surrounding rectangles.
In my case, if the bridge is wide enough on the Y axis, it will be poorly sorted between the characters on and under the bridge.

V3. I can make the game entirely in 3D
and use Z-Buffer, which is designed to solve the problems mentioned above.
But before I take this leap, I would like to be sure I have explored all the other possibilities (2D).


I searched the internet high nad low for a tutorial or article on this, and surprisingly, I didn't find one that would work for me.

I will be very grateful for any advice.

Sorting questions

I am studying sorting in an algorithm course. I need a hint because I really don't know where to start with these next two questions. Any help is appreciated.

Suppose that all the integers are stored in a single linked list.

  1. Write a Sort function whose input is a pointer to the first node of a list of unknown length.

    List sorting (node ​​* header)

    Your method must return its elements in a sorted list. Again, your method must not create new nodes and must have a time complexity O (nlogn).

  2. Suppose that two (unsorted) arrays A (0 … n – 1) and B (0 … n – 1) together contain 2n distinct numbers. Describe a method for constructing an array C (O..n – 1) such that for each index i E (O..n -1), A (i) is greater than exactly C (i) elements in the array B (0 … n – 1). Your method can use O (n) extra space and must have O (nlogn) running.

php – Custom sorting in publication columns by ACF Pro Select Field

I am adding a custom column to the admin screen for a custom post type. The custom column should display the options selected in an ACF Pro selection field. Instead, it always fires as containing the value, which suggests to me that instead of pulling only the options selected for each post, it pulls all of the available values ​​for the ACF Pro selection field.

I'm just … not sure how to fix this. What am I wrong here?

add_action( 'manage_asgallery_posts_custom_column', 'asgallery_new_column', 10, 2);
function asgallery_new_column( $column_name, $post_id ) {
    if( $column_name == 'featured_posts' ) {
        $a = get_field_object('field_5dbcb72cad947', $post_id); 
        $a_value = $a('value');
        //$case_study = get_post_meta( $post_id, 'case_study_category' );
        if(strpos($a_value, 'Repair') !== false) {
            echo 'Repair'; 
        }
        else { echo 'None'; }
    }
}

How to create a sorting panel with links in a row instead of a drop-down list?

Anyone know how to replace the drop-down list with links or buttons? Example:
enter description of image here

I tried to do it via CSS but I didn't get the result. It seems to be done via Html / PHP.

This is a piece of code from application / design / frontend /Seller/Theme/Magento_Catalog/templates/product/list/toolbar/sorter.phtml

Thanks for your thoughts.

meta-query – WooCommerce sorting from bottom to top must be applied to the prices of the range when I use BETWEEN meta_query on the shop page

WooCommerce sorting from bottom to top must be applied to the prices of the range when I use BETWEEN meta_query on the shop page.

this should be against the variation products at the moment, the sorting relates to the minimum price of the variation product and not to the selected price of the variation product along the price of the range.
Because I show that the price of variation exists between the prices of the range via filters on the page of the shop.

asymptotic – worst execution time for lexicographic sorting of a list of n strings of length n each using merge sort

This same question has been asked here so many times by several people. This is a problem that was raised during an entrance exam.

And I'm having a hard time digesting the right answer to this problem. Why is my approach incorrect?

Here is my approach:
The division part of sorting by merge recursively divides the list of strings into sublists with half a number of strings each.

Next, the merge part takes sorted lists from two of its child nodes and merges them into its own sorted list. This merge propagates upwards to the root and the entire list is finally sorted.

The merge works this way:
The two lists of children have together $ (n1 + n2) = O (n) $ strings. And to compare two strings as part of the merger, we have to compare at most $ n $ positions (since the strings are long $ n $).

The merger therefore takes $ theta (n * n) = theta (n ^ 2) $

Now the recurrence equation looks like: $ T (n) = 2T (n / 2) + thêta (n ^ 2) $

Using the master method $ n ^ {log_22} = n $
And $ f (n) = theta (n ^ 2) = Omega (n ^ {log_22}) $

This is case 3 of the Master method. so $ T (n) = theta (f (n)) = theta (n ^ 2) $ should be the correct answer.

algorithms – Sorting of N numbers by digits

I have N numbers and I want to sort each number by digit. (In my original problem, I want to make as many of them (greedy approach))
For example –
If we have 5 numbers
9 1000 845 8000 56
In the first step, I will choose 9 because 9 is the highest of all the first digits

In the second step (as 9 is already selected), the next highest first digit is 8, but when 2 or more numbers have the same digit, I will compare their next digit, so I will choose 845.

If I sort, I will get the following result
9,845 8,000 56 1,000.

My question is how can this be implemented in C ++?

Thanks in advance