Stored procedures for selecting the data from databse & displaying on selction

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anuragvatsa
    New Member
    • Dec 2009
    • 4

    #1

    Stored procedures for selecting the data from databse & displaying on selction

    Hi,
    I have 4 columns workID, Description, work & Rework . On the basis these four columns i have to generate four more columns as total Work,%work, %Rework, %Total Work. we have some dummy data. So Now my question is how to write stored pocedure to select in case of the above scenaraio.
    Thnks.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    If I am understanding you correctly, you don't really need a procedure.
    You could simply do something like:
    [code=sql]SELECT
    `id`, `description`, `work`, `rework`,
    (`work` + `rework`) AS `total_work`,
    (`work` / (`work` + `rework`) * 100) AS `% work`,
    (`rework` / (`work` + `rework`) * 100) AS `% rework`,
    ((`work` + `rework`) / (SELECT SUM(`work` + `rework`) FROM `work_table`) * 100) AS `% total work`
    FROM `work_table`;[/code]

    Comment

    Working...