Comparison between decimal numbers

-1

I have 2 posts in a table, with prices 500.00 and 88.98. When I run to sort at the highest price, Mysql returns me that 88.98 is greater than 500.00, the price field is a string, why does this happen?

    
asked by anonymous 16.12.2016 / 06:44

2 answers

2

Because 5 comes before 8, as it is string it is comparing the characters. Change the data type to decimal.

    
16.12.2016 / 10:49
2

You can follow what Douglas said, from the table structure to change the type of data for this field. As you can also convert from select to fetch the data using this syntax:

SELECT seu_campo FROM 'sua_tabela'
ORDER BY CONVERT(seu_campo ,DECIMAL(10,2)) ASC
;
    
16.12.2016 / 11:21
___ ___ Find erkimt values between two prefixes and exchange each other [closed] ______ qstntxt ___

I'm developing an application where you have to find a set value and literally walk 19 homes.

13000000 736363645C736363645F
6178747265653030311300000073
6363645F6178747265653030315F

  • Search for value from: 13000000
  • Floor of: 13000000 up to: 736363645C736363645F617874726565303031 (Or until you find another value 13)

Looking like this:

13000000 736363645C736363645F
617874726565303031 1300000073
6363645F6178747265653030315F

  • Search for another value: 13000000

Looking like this:

13000000736363645C736363645F
617874726565303031 13000000 73
6363645F6178747265653030315F

  • Floor of new value: 13000000 to the other value: 736363645F6178747265653030315F

Looking like this:

13000000736363645C736363645F
61787472656530303113000000 73
6363645F6178747265653030315F

Then, exchange one value for the other: 736363645C736363645F
61787472656530303 for 736363645F6178747265653030315F

Doing a loop by repeating the same function throughout the file.

======================== Edit

So:

13-00-00-00- 73-63-63-64-5C-73-63-63-64-5F-61-78-74-72-65-65-30-30- 31 -13-00-00-00- 73-63-63-64-5F-61-78-74-72-65-65-30-30-31-5F

Looking like this:

13-00-00-00- 73-63-63-64-5F-61-78-74-72-65-65-30-30-31-5F -13-00-00-00- 73-63-63-64-5C-73-63-63-64-5F-61-78-74-72-65-65-30-30-31

NOTE: I changed the value above after the "13-00-00-00" down

============================ @ I tried something similar to this:

%pre%     
______ azszpr140100 ___

A simple way is regular expression, using %code% :

%pre%

In the case, I made you a regular expression with two groups: one internal (to take the 19 values individually) and one external, to get all 19 values at once.

I made a Fiddle .

Note that in Fiddle, %code% is exactly what you're looking for.

About invert to %code% the simple way is to implement this function ( best answer from here ):

%pre%

Therefore:

%pre%

Now I understand what you want. You want to locate the groups two by two, and then invert them.

This changes the regular expression, because you need to necessarily find two groups:

%pre%

Find the largest group ( %code% ) and do another regular expression search on it. You will get two groups.

Just invert them and mount another %code% .

    
______ azszpr140105 ___

I tried to do something that seems to be what you want. You may have problems because the problem is not well defined. If I improve the setting, I can change it a bit and make a final, more organized version. I made a version with question originals and without the dashes as it was after the edit.

%pre%

See working on dotNetFiddle .

    
___ SQL + Left Join