Query using WHERE

-1

I need to query in a table called controls:

I have the column CH which is the hourly load in minutes and I have the column SETOR which are the sectors that participated in some training.

I need to make an appointment where it brings me the total (sum) of minutes per sector. Sector 7 would for example be 1080 result.

I did so: SELECT round(SUM(ch)) FROM controles WHERE setor = '7';

But I do not get any results.

    
asked by anonymous 21.08.2018 / 15:37

1 answer

2

If you want to find all the records where the setor field has a certain number you would have to do this:

Note: Understanding that your field is Varchar or something equivalent to the type of text (String).

SELECT round(SUM(ch)) FROM controles WHERE setor like '%"7"%';

Explaining

Example 1

Select * from Tabela where nome LIKE ‘a%’;
  

The above character '%' indicates that we are looking for all   names beginning with the letter 'a'.

Example 2

Select * from Tabela where nome LIKE ‘%a’;
  

The above character '%' indicates that we are looking for all   the names that have the last letter 'a'.

Example 3

Select * from Tabela where nome LIKE ‘%a%’;
  

The two characters above '%' indicate that we are looking for all   the names that have the letter 'a' in any part of the text.

    
21.08.2018 / 15:50