I am trying to get the total field below to be the count of fields that are not calculated to equal 0. Instead of 1 I am looking for a total of 7 to display. The expression for the calculation of Column B is Sum(Fields!Hours.Value)/40. The expression for my Total field is: SUM(IIF(Sum(Fields!Hours.Value)/40 <>0,1 ,0))
-Column A Column B -BA #1 1.175 -BA #2 1.04375 -BA #3 1.375 -BA #4 0 -BA #5 1.1125 -BA #6 1.0375 -BA #7 1.05 -BA #8 0 -BA #9 1.40625 -BA #10 0 -Total 1
I have tried and just do not know what I am doing wrong here. Any help please? Much appreciated!
Related
I keep on looking around StackOverflow for a similar question but it seems that I can't find one. I would like to know the difference between timestamps in different rows grouped by employee ID.
Time Logs table:
id timestamp log_type
1 2019-06-19 12:34:50 log_in
2 2019-06-19 13:12:46 start_break
3 2019-06-19 13:13:56 end_break
4 2019-06-19 17:23:40 start_break
5 2019-06-19 17:44:36 end_break
6 2019-06-19 19:00:04 start_break
7 2019-06-19 19:03:17 end_break
8 2019-06-19 20:05:54 log_out
What I'm trying to accomplish is to calculate all duration of breaks. In this case, 1st break (id #2 and #3) is 1 minute and 10 seconds, 2nd break (id #4 and #5) is 20 minutes and 56 seconds, 3rd break (id #6 and #7) is 3 minutes and 13 seconds thus with the total of 25 minutes and 19 seconds.
Thanks for helping out! Much appreciated.
You can try below -
DEMO
select SEC_TO_TIME(sum(diff)) as result from
(
select
timestampdiff(second,min(case when log_tpe='start_break' then timestamps end) ,
min(case when log_tpe='end_break' then timestamps end)) as diff
from t
group by date(timestamps),hour(timestamps)
)A
OUTPUT:
result
00:25:19
good morning guys, I have this table named 'soccer_team'
id first_name surname player_number
1 Alexis Sanchez 7
2 Petr Cech 33
3 Hector Bellerin 24
4 Olivier Giroud 12
5 Theo Walcott 14
6 Santi Cazorla 19
if I launch this command,
SELECT CONCAT(first_name,' ',surname,' #',player_number) as 'i' from soccer_team order by player_number
it gives me
i
Alexis Sanchez #7
Olivier Giroud #12
Theo Walcott #14
Santi Cazorla #19
Hector Bellerin #24
Petr Cech #33
which is correct
however when I run
SELECT GROUP_CONCAT(i,' ') as 'players'
FROM (SELECT CONCAT(first_name,' ',surname,' #',player_number) as 'i'
from soccer_team
order by player_number
) as a;
it gives me
players
Alexis Sanchez #7 ;Petr Cech #33 ;Hector Bellerin #24 ;Olivier Giroud #12 ;Theo Walcott #14 ;Santi Cazorla #19
while it should be
players
Alexis Sanchez #7; Olivier Giroud #12; Theo Walcott #14; Santi Cazorla #19; Hector Bellerin #24; Petr Cech #33
**
how to solve the problem I know, I wanted to know why this happens
**
UPDATE
I know how to solve it, what interests me is because it works in this
way
You can specify the order inside GROUP_CONCAT provided that you include player_number in the subquery.
SELECT GROUP_CONCAT(i ORDER BY player_number ASC SEPARATOR ' ') as 'players'
FROM (
SELECT CONCAT(first_name,' ',surname,' #',player_number) as 'i' ,player_number
from soccer_team
) as a;
Here's a Demo.
Actually, you can simplify by removing the subquery which will still give you the same result
SELECT GROUP_CONCAT(CONCAT(first_name,' ',surname,' #',player_number)
ORDER BY player_number ASC SEPARATOR ' ') as 'players'
FROM soccerteam
Here's a Demo.
I want for each projet to have the highest reach of etape.
select nometape, description
from etape
where idetape in(
select max(idetape) from etapexprojet)
where distinct(idprojet));
my tab look like
etape
idetape/nometape/description
1/debut/commencement
2/rédaction/avancement
3/fin/fin
etapexprojet
idetape/idprojet
1/1
2/1
1/2
2/2
3/2
1/3
I got an error on the line 5 but i don'T know how to overcome it
I need to get an aggregated result per MODEL that Sums the total count of previously filtered items from a previous query:
SELECT model, ratio, if(count(model)>=3,3,count(model)) AS gearcount
FROM zfgearinv
WHERE allocated = 0 AND sold = 0
GROUP BY model, ratio
ORDER BY model
In this query I am only showing <=3 items and then I only want to show the SUM of those items PER MODEL:
MODEL RATIO GEARCOUNT
ZF 220A 1.23 2
ZF 220A 1.53 3
ZF 220A 1.75 3
ZF 220A 2 1
ZF 220A 2.45 2
ZF 220V 1.5 3
ZF 220V 1.75 1
ZF 220V 2 3
ZF 220V 2.5 3
So my final out put should read:
MODEL TOTAL
ZF 220A 11
ZF 220V 10
all you need to do is wrap that query with an outer query where you do the SUM of your gearcount
SELECT model as MODEL, SUM(gearcount) as TOTAL
FROM
( SELECT model, ratio, if(count(model)>=3,3,count(model)) AS gearcount
FROM zfgearinv
WHERE allocated = 0 AND sold = 0
GROUP BY model, ratio
) t
GROUP BY model
ORDER BY model
Problem: I’m going to explain this problem using the Sakila sample database and it data so it is easier for you. Ok, so my question is how can I compare the current record to the next in the same table in terms of 'datetime'. This is how the table looks like:
payment_id customer_id staff_id rental_id amount payment_date last_update
1 1 1 76 2.99 25/05/2005 11:30:37 15/02/2006 22:12:30
2 1 1 573 0.99 28/05/2005 10:35:23 15/02/2006 22:12:30
3 1 1 1185 5.99 15/06/2005 00:54:12 15/02/2006 22:12:30
4 1 2 1422 0.99 15/06/2005 18:02:53 15/02/2006 22:12:30
5 1 2 1476 9.99 15/06/2005 21:08:46 15/02/2006 22:12:30
Using the above explanation in this sample, for each ‘staff_id’, how can I compare the current row with the next (using ‘payment_date’ for current and next), so it brings only the pair of records where the amount of the current record is the same as the next (something like current.amount = next.amount). This means that each record should be compared to the next of the same ‘staff_id’, and so on.
I’m currently using this query, which do the job, but it takes for ever. I know it works good because I setted LIMIT 3 and it brought the correct ones (you can test it as well if you have the Sakila sample database):
SELECT * FROM payment a
JOIN payment b ON a.staff_id = b.staff_id AND a.payment_date > b.payment_date AND a.amount = b.amount
LEFT JOIN payment c ON a.staff_id = c.staff_id AND c.payment_date < a.payment_date AND c.payment_date > b.payment_date
WHERE c.payment_id IS NULL
LIMIT 3;
Could you please help me?