Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6110123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:28:49+00:00 2026-05-23T14:28:49+00:00

I got this table named tb_stock ID AMOUNT FLAG LAST_AMOUNT 1 5 N 0

  • 0

I got this table named tb_stock

ID AMOUNT FLAG LAST_AMOUNT
1   5     N    0                
2   0     Y    8                
3   0     Y    7                
4   6     N    0

Right now i want to sum the value based on the FLAG value. For example if the FLAG values is N, it will sum from the AMOUNT field and if the FLAG value is Y, it will sum from the LAST_AMOUNT field.

So the total amount would be 26 (5 + 8 + 7 + 6).

Is this can be achieve with just use mysql or it will involve php as well?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:28:49+00:00Added an answer on May 23, 2026 at 2:28 pm
    SELECT SUM(CASE WHEN FLAG = 'Y' THEN LAST_AMOUNT ELSE AMOUNT END) AS TOTAL
    FROM tb_stock
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example I got this 2 table dbo.fc_states StateId Name 6316 Alberta 6317 British
This is the second time I've got 4294967294 value in this table. I have
I've got a table that includes a column named valid. This has caused a
i've got a database with a table named PropertyValues where i store every value
I got a database named accounts and account table inside of this database, Also
Got this: Table a ID RelatedBs 1 NULL 2 NULL Table b AID ID
I've got this table with an int(11) column and hundreds of millions of rows.
I got this create table statement; $sql = CREATE TABLE TermsFinal( `seed` INT NOT
So I've got this audit table, looks like this: USE [DatabaseName] GO /****** Object:
I've got this really basic table structure: Posts PostXTags PostTags There is a 1-n

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.