I want to add total sum of former broken and former crack for line 1 - 20 in December 2021. but now I only know this code
SELECT `line`, SUM(`FormerBroken`), SUM(`FormerCrack`) FROM `line_check` WHERE `Month` = '2021-12' AND `Line` = '1'
So is there any way that i can add line='2' , line='3',line='4'
my table for reference
| Date | Line | Former Broken | Former Crack |
|---|---|---|---|
| 1/12 | 1 | 3 | 2 |
| 2/12 | 2 | 5 | 4 |
| 3/12 | 3 | 7 | 6 |
| 4/12 | 4 | 9 | 8 |
| 5/12 | 5 | 10 | 10 |
| 6/12 | 1 | 3 | 2 |
| 7/12 | 2 | 5 | 4 |
| 8/12 | 3 | 7 | 6 |
| 9/12 | 4 | 9 | 8 |
CodePudding user response:
You can use IN(...).
Example:
SELECT * FROM table WHERE someValue IN (1, 2, 3, 4);
Tailored to your existing query:
SELECT `line`, SUM(`FormerBroken`), SUM(`FormerCrack`) FROM `line_check` WHERE `Month` = '2021-12' AND `Line` IN ('1', '2', '3', '4');
