Jump to content

[Guide]Sql Statements


vampir

Recommended Posts

Hello, i will teach u something usefull today

Look at this table: http://imageshack.us/photo/my-images/191/imagenqg.png/ lets say left table is named "characters" and right table is named "clans"

SELECT

Ok so lets do something easy, lets take all variables from online characters:

SELECT * FROM characters WHERE online=1

* means every column(ID, name, title etc), so thats easy right?

 

So now lets get every online character with the clan

SELECT * FROM characters WHERE online=1 AND clanId>0

Thats easy too, we will have 2 results

 

Now we will take every Name of the character, but i want them sorted by PvpPoints, so character with most pvp points will be at first place:

SELECT Name FROM characters ORDER BY PvpKills ASC

We will have "Vampir, Koko, Tester, PolakPl" as result. ASC - means from a to z/lowest to biggest, DESC means from z-a/biggest to lowest.

 

Hmm and what if i want to take just top 3 guys?

SELECT TOP 3 Name FROM characters ORDER BY PvpKills ASC

Thats simple :P

 

Ok, now lets take Titles of characters, that have got clan, or their sex is 1

SELECT Title FROM characters WHERE clanId>0 OR Sex=1

Piece of cake

 

We have got some different things also, like taking average:

SELECT AVG(PkKills) FROM characters

It will give us: 12, since (4+12+0+32)/4=12

You can also look at Count(), Max(), Min(), Sum()

 

Sometimes it happends, that we need to get 2 tables in same time, like for example get name of player's clan, and its not in same table, so thats a bit harder:

SELECT clans.Name, characters.Name FROM characters INNER JOIN clans ON characters.clanId=clans.clanId WHERE characters.clanId>0

Thats a bit complicated, isnt it? So we are taking Name from table clans and Name from table characters.

We need to connect tables, so after FROM we put name of first table, later INNER JOIN and after that name of 2nd table.

After that we put word ON and choose columns that are connected(here clanId, sometimes we may have in characters char_id and in other table also char_id, so thats what we need to connect), so we do it like this: table.column_name=2ndTable.2ndColumn_name

Column names doesnt have to be different!

 

UPDATE

Ok, lets leave that boring SELECT, i will also teach u how to update, add and remove records.

UPDATE characters SET PvpKills=PvpKills+1

It will add 1 pvp Point to every character in database.

So first UPDATE, later name of the table, later SET and what we wanna do

 

UPDATE characters SET Title='' WHERE clanId=0

This will set every character title empty, if he doesnt have a clan.

 

Insert

Now lets add some new Records

INSERT INTO clans VALUES (19,'Losers', 1, 0, '', 0, 0)

Ok so i added new Clan to clans table, id=19, name=Losers, level=1, reputation=0, ally name is empty, castle and fortress is set to 0

 

if we want to put only some values and make the rest be default, do this:

INSERT INTO clans(clanId, Name, Level) VALUES (20, 'NewClan', 2)

So clanId will be 20, name=NewClan, and level=2, rest will be set to default so it will probably be null or 0

 

DELETE

The last thing will be deleting records.

DELETE FROM clans WHERE hasCastle=0

it will remove all clans, that doesnt have castle.

 

What if we wanna remove everything?

DELETE FROM clans

 

Thats all, thx for reading it, i know its very basic thing but maybe somebody will find it usefull, if u wanna learn more http://www.w3schools.com/sql/

Feel free to ask about anything :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • Instead of using encedc on it, try renaming it to "Icon.u" instead of "Icon.utx", and put it in your System folder. If it still crashes, the problem might be with your unrealed.
    • How's the project doing? Is there any news? It really interesting 🤔
    • thx for answer, i tried and woks encrypting, but i still having crashes 😞 i changed the icon in skillgrp.dat from "icon.skill0003" to "Myicons.misil" as i saved the file before endec and nothing. this is the report i got
    • New Season coming May 2024! First post updated      Website: L2Kain.net  Discord: https://discord.gg/l2kain  Wiki: https://info.kain.ws/   Important Dates   Server Start: TBD  Open Beta Test: 10th of May 2024!   Basic Information     Briefly about the concept of the server! We decided to move away from the standard Mid-Rate server concept and keep the mechanics of our beloved Lineage 2 that everyone loves! Massive battles for epic bosses, battles for profitable farming locations, resource spoilage and equipment crafting, daily instances, a balanced economy and much more. This server is build as a Craft-PvP concept. The goal is to gather players with a variety of preferences in the game and make a high-quality and interesting server with alternative character development options. We are well aware that "grinding" is an integral part of the game, but we diluted the boring and the same type of farming with interesting solutions and non-standard mechanics!   We have prepared a new High Five x25 on Modern Client for you. This server will be another step in the development of the platform and the project as a whole! Your appeals to those. support was not ignored, which means the new server will be even better than the previous one!      ⭐ Promotions and Bonuses for new players!     ⭐ Events and Giveaways daily!   ⭐ Rewards for Voting!   ℹ️ Server Rates Learn more about server rates! Server rates are configured in such a way that farming is best rewarded. Adena, drops, quests, various rewards and prices in the game store are well balanced among themselves!   Basic Server Rates:  ⭐ Experience & Skill Points - x25  ⭐ Adena Drop - x15 & Fixed Chance 66%  ⭐ Drop Rates - x10  ⭐ Spoil Rates - x10   Crafting keys, recipes drop & spoil with fixed amount from 2 to 3 and increased chances on all locations and quests  related to farm them.  ⭐ Quest Rates - x5  ⭐ Fortresses & Sieges - x5  ⭐ Raid Bosses & Epic Bosses - x1  ⭐ Weight Limit - x10      Connect with Us:  Discord: https://discord.gg/l2kain  Facebook: https://www.facebook.com/KainLineage2  TikTok: https://www.tiktok.com/@l2kain.net  YouTube: https://www.youtube.com/@Lineage2Kain
  • Topics

×
×
  • Create New...