chami2015

Well-known member
  • Jul 14, 2015
    7,042
    8,292
    113


    මේකයි කතන්දරේ,

    ඇත්තම සිද්ධිය උදාහරණෙට ගන්නම්කො,

    ටේබල් 3ක් තියෙනවා, එකක රටවල් හැම එකක්ම තියෙනවා Primary Key එක CountryID(Auto Increment එකක්) අනිත් ටේබල් එකේ තියෙනවා Currency Units හැම රටකම, ඒ ටේබල් දෙක Query වලින් Join කරල තියෙන්නේ, එයිට අමතරව Exchange Rate Table එක වෙනම තියෙනවා, ඒකෙ තියෙන Fields තමයි ID(Auto Increment),Country ID, Rate, Updated Date මෙන්න මෙතැන තමයි කොස්ස තියෙන්නේ, ඔය ටේබල් එකේ රෙකෝඩ්ස් මල්ටිපල් වදිනවා, ඒ කියන්නේ මෙහෙමයි,
    1USD = 155LKR කියල 10.09PM ට අප්ඩේට් වෙනවා, ආයිත් 1USD = 155.50 කියලා 11.00ට අප්ඩේට් වෙනවා, Currency Unit හැම එකකම History එක මේ ටේබල් එකේ වදිනවා,
    මේ ටේබල් 3ම Join කරල තියෙන්නෙ,
    දැන් මට වෙන්න ඕන මේකයි,
    මේ Exchange Rate ටේබල් එකේ මේ වගේ රෙකෝඩ් ටිකක් තියෙනවා කියල හිතන්න(ජොයින් කරයින් පස්සෙ),
    155 LKR 10.13
    155.50 LKR 10.20
    1.2 AUD 09.53
    1.3 AUD 09.52
    0.9 EUR 10.13
    මෙන්න මේ වගේ ඩේටා ටිකක් ටේබල් එකේ තියේ නම් මට ඕන මේ විදියෙ Result එකක් ගන්න,
    155.50 LKR 10.20
    1.2 AUD 09.53
    0.9 EUR 10.13

    කෙටියෙන්ම කිව්වොත් හැම කරන්සි රේට් එකකම අන්තිමටම අප්ඩේට් වුණ රෙකෝඩ් එක ගන්න මෙන්න මේ වගේ,

    මේකට Stored Procedure එකක් ලියන්න ඕන, මේක ලියන විදිය දන්න කෙනෙක් හෙල්ප් එකක් දීපං බං, GROUP BY වලින් නේද වැඩේ කරන්න වෙන්නෙ?
     

    sad32

    Active member
  • Jul 5, 2010
    221
    68
    28
    Counry code eken group karala max updated date eka gattanam hari wage... ekath ekka anith table join karala view ekak gahuwanan goda daganna puluwn wei man hitanne....
     
    • Like
    Reactions: chami2015

    deepwater

    Well-known member
  • Aug 14, 2015
    848
    484
    63
    Mulinma ube table structure eka oita wada improve karanta puluwan. Oya currency code table eka galawala eka country table ekema column ekakata dammaki. Performance wise meka maara speed.

    Ube prashneta uththare, procedure ekak one na simple query ekak athi.

    Select c.countryid , d.code, e.rate
    From country c, currencycode d, exrate e
    Where c.countryid = d.countryid
    and c.countryid = e.countryid
    Group by c.countryid, e.id
    Having e.id = max(e.id)
    Order by e.id

    Mama meka test kare na, poddak test karala balapan.
    Ubata wenta one country wise group unata passe max id eka thiyana rate row eka each group eke. Having eka dala thiyenne ekata. Poddak check karala, one nam change karala ganin. Habai basic structure eka query eke me wage thama
     

    Sword_Fish

    Well-known member
  • Dec 28, 2015
    787
    562
    113
    Sample : Oracle sql syntax

    You can do it like this (I have used Oracle, You may change this Sql syntax according to your database )


    1) Tables

    Countries
    Countries.jpg


    Currency_Units
    CURRENCY_UNITS.jpg


    Rates
    RATES.jpg


    Normal Join Query

    Without_Filetring.jpg


    Final Query to get your required result set

    Modifed_Query.jpg


    :):):)And, there are several ways to do this.
     
    Last edited:

    chami2015

    Well-known member
  • Jul 14, 2015
    7,042
    8,292
    113
    හෙල්ප් එකක් ඉල්ලපු ගමන් මේ වගේ පැනල උදව් කරන සෙට් එකක් එලකිරි එකේ ඉන්න එක ගැන ඇත්තටම මට සතුටුයි බං,

    වැඩේ කොහොම හරි කරගත්ත බං, කට්ටිය එවල තිබ්බ ලින්ක් බලලා ඒවගෙන් පොඩි අදහසක් ගත්ත දැන් සුපිරියටම වැඩේ වෙනවා,

    මම ස්ක්‍රීන් ෂොට් ටික යටින් දාන්නම්,
    Capture.JPG
    capture1.jpg


    උදව් කරපු හැමෝටම ස්තූතියි සහෝ!:)
     

    chami2015

    Well-known member
  • Jul 14, 2015
    7,042
    8,292
    113
    Mulinma ube table structure eka oita wada improve karanta puluwan. Oya currency code table eka galawala eka country table ekema column ekakata dammaki. Performance wise meka maara speed.

    Ube prashneta uththare, procedure ekak one na simple query ekak athi.

    Select c.countryid , d.code, e.rate
    From country c, currencycode d, exrate e
    Where c.countryid = d.countryid
    and c.countryid = e.countryid
    Group by c.countryid, e.id
    Having e.id = max(e.id)
    Order by e.id

    Mama meka test kare na, poddak test karala balapan.
    Ubata wenta one country wise group unata passe max id eka thiyana rate row eka each group eke. Having eka dala thiyenne ekata. Poddak check karala, one nam change karala ganin. Habai basic structure eka query eke me wage thama

    Thanks macho help ekata
    wade karagaththa, mama code eken screenshot ekak damma bn #11 weni comment eke,

    Currency table eka galawala country ekema damme naththe eka hethuwak uda bn, mama net eke hoyala baluwama samahara currency unit ratawal deka thunaka use wenawa bn, eh kiwwe Pound eka ratawal 2ka use wenawa, eka avoid karanna hondama structure eka meka kiyala hithagena thamai bn Table 3k gaththe, Countries, Currency & Exchange Rates

    Thanks macho! :)
     

    chami2015

    Well-known member
  • Jul 14, 2015
    7,042
    8,292
    113
    You can do it like this (I have used Oracle, You may change this Sql syntax according to your database )


    1) Tables

    Countries
    Countries.jpg


    Currency_Units
    CURRENCY_UNITS.jpg


    Rates
    RATES.jpg


    Normal Join Query

    Without_Filetring.jpg


    Final Query to get your required result set

    Modifed_Query.jpg


    :):):)And, there are several ways to do this.

    Godak mahansi wela explain karanna
    Thank you very much macho
    aththatama unbala gana sathutui:yes:

    wade karagaththa bn, uda screenshot dala thiyanawa bn, unbalage help eken thamai karagaththe wade, code ehe mehe karala search karala baluwa bn,
     

    Sword_Fish

    Well-known member
  • Dec 28, 2015
    787
    562
    113
    Godak mahansi wela explain karanna
    Thank you very much macho
    aththatama unbala gana sathutui:yes:

    wade karagaththa bn, uda screenshot dala thiyanawa bn, unbalage help eken thamai karagaththe wade, code ehe mehe karala search karala baluwa bn,

    Ela ela Macho :D:D
     
    Last edited:

    saminda_1980

    Well-known member
  • Feb 23, 2018
    1,841
    139
    63
    පොතේ තියෙන විදිහටම වගේ කරන්නෙන්.
    නිකන් අහන්නේ අප්ඩේට් එකක් කරන්න ඇප් කොඩ් වල රෝස් කියක් යනවාද?:)
    එල
     
    Last edited:

    chami2015

    Well-known member
  • Jul 14, 2015
    7,042
    8,292
    113
    පොතේ තියෙන විදිහටම වගේ කරන්නෙන්.
    නිකන් අහන්නේ අප්ඩේට් එකක් කරන්න ඇප් කොඩ් වල රෝස් කියක් යනවාද?:)
    එල

    3-Tier Architecture ekata bn karanne, godak adu lines ganak yanne, load eka balance wenawa SP ekatath ekkama, Data Access Layer eka wenama thiyana nisa mara lesei bn upgrade ekak hema awoth,

    ai bn ehema ahuwe? ;)