Raised This Month: $12 Target: $400
 3% 

Solved [CSGO] Help for mysql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dr.Mohammad
Senior Member
Join Date: Jan 2016
Location: CSGO Servers
Old 02-17-2019 , 14:14   [CSGO] Help for mysql
Reply With Quote #1

hi guys!!

my cod:
PHP Code:
Format(querysizeof(query), "%s ORDER BY CAST(CAST(kills as float)/CAST (deaths as float) as float) DESC"query); 
error:
HTML Code:
Query Fail: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'float)/CAST (deaths as float) as float) DESC' at line 1
please help.

Last edited by Dr.Mohammad; 02-21-2019 at 04:20.
Dr.Mohammad is offline
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 02-17-2019 , 14:58   Re: [CSGO] Help for mysql
Reply With Quote #2

Because CAST() is a function you cannot have a space between CAST and () so you need to change the third CAST to /CAST(deaths as decimal) and change the other two floats to decimal because CAST doesn't work with the float datatype, should also add semicolon at end of query.

Example query:
PHP Code:
SELECT FROM test ORDER BY CAST(CAST(kills AS DECIMAL)/CAST(deaths as DECIMAL) AS DECIMALDESC
CliptonHeist is offline
Dr.Mohammad
Senior Member
Join Date: Jan 2016
Location: CSGO Servers
Old 02-18-2019 , 15:19   Re: [CSGO] Help for mysql
Reply With Quote #3

Quote:
Originally Posted by CliptonHeist View Post
Because CAST() is a function you cannot have a space between CAST and () so you need to change the third CAST to /CAST(deaths as decimal) and change the other two floats to decimal because CAST doesn't work with the float datatype, should also add semicolon at end of query.

Example query:
PHP Code:
SELECT FROM test ORDER BY CAST(CAST(kills AS DECIMAL)/CAST(deaths as DECIMAL) AS DECIMALDESC
thank you for help :X

true this??
PHP Code:
Format(querysizeof(query), "%s ORDER BY CAST(CAST(kills AS DECIMAL)/CAST(deaths as DECIMAL) AS DECIMAL) DESC"query); 

Last edited by Dr.Mohammad; 02-18-2019 at 15:20.
Dr.Mohammad is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 02-20-2019 , 13:15   Re: [CSGO] Help for mysql
Reply With Quote #4

Did it work?

I don't think you need all these casts, and the outer cast, since when both numbers are decimal the result will be decimal anyway

You can try these others "selects" if they work would be faster since it will consume less CPU

Code:
SELECT * FROM test ORDER BY CAST(kills AS DECIMAL)/CAST(deaths as DECIMAL) DESC;
Code:
SELECT * FROM test ORDER BY CAST(kills / deaths) as DECIMAL DESC;
But looking your needs, I think you must add another "order by desc" because you can have scenarios where both kills/death results in same value, so you need do another check and order by the most client kills

I made and example below
https://paiza.io/projects/PrMhFtm8Mv...language=mysql

In my opinion you just need do that:

Code:
ORDER BY kills/deaths DESC, kills DESC;

Last edited by Marttt; 02-20-2019 at 13:30.
Marttt is offline
Dr.Mohammad
Senior Member
Join Date: Jan 2016
Location: CSGO Servers
Old 02-21-2019 , 04:20   Re: [CSGO] Help for mysql
Reply With Quote #5

Quote:
Originally Posted by Marttt View Post
Did it work?

I don't think you need all these casts, and the outer cast, since when both numbers are decimal the result will be decimal anyway

You can try these others "selects" if they work would be faster since it will consume less CPU

Code:
SELECT * FROM test ORDER BY CAST(kills AS DECIMAL)/CAST(deaths as DECIMAL) DESC;
Code:
SELECT * FROM test ORDER BY CAST(kills / deaths) as DECIMAL DESC;
But looking your needs, I think you must add another "order by desc" because you can have scenarios where both kills/death results in same value, so you need do another check and order by the most client kills

I made and example below
https://paiza.io/projects/PrMhFtm8Mv...language=mysql

In my opinion you just need do that:

Code:
ORDER BY kills/deaths DESC, kills DESC;
nice!!
thank you!!

I used this line:
PHP Code:
Format(querysizeof(query), "%s  ORDER BY kills/deaths DESC"query); 
thank you guys :X
Dr.Mohammad is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:37.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode