Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
D

Developer Account

@Developer Account
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How do I calculate the column in PHP union all function
    D Developer Account

    I have an issue while calculating the column-like bank statement. actually, I am trying to calculate Opening Balance/today In /today Out / Closing Bal in MySQL PHP. I have two tables. material_infor `IN +` entry and material_approvefor `OUT -`. I am considering my opening balance was `123`.

    I am new in PHP and I am here using Union All function. Please help me to create the function for getting Opening / In today / out today/closing calculation in my code.

    `table- material_in`

    id components_key insert_date credit
    1 12345 2021-04-16 100
    2 12345 2021-04-16 50

    `table- material_approve`

    id components_key insert_date debit
    1 12345 2021-04-16 30
    2 12345 2021-04-16 2

    <pre>I am trying the code -

    SELECT
        \`u\`.\`component\_key\`,
        \`u\`.\`insert\_date\`,
        \`u\`.\`transaction\_qty\`
    FROM
        (
        SELECT
            \`components\_key\` AS \`component\_key\`,
            \`insert\_date\`,
            \`credit\` AS \`transaction\_qty\`
        FROM
            \`material\_in\`
        UNION ALL
        SELECT
            \`components\_key\`,
            \`insert\_date\`,
            \`debit\` AS \`transaction\_qty\`
        FROM
            \`material\_approve\`
        ) u
    WHERE
        \`u\`.\`component\_key\` = '12345'
    ORDER BY
        \`u\`.\`insert\_date\`
    DESC
    

    the output comes -

    components_key insert_date transaction_qty
    12345 2021-04-16 100
    12345 2021-04-16 50
    12345 2021-04-16 30
    12345 2021-04-16 2

    `output will be-`

    components_key insert_date openbal today_in today_out closebal
    12345 2021-04-16 123 100 30 193
    12345 2021-04-16 193 243 2 241

    //openbal + today_in - today_out = closebal

    Linux, Apache, MySQL, PHP help php mysql question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups