I have a database table WysTeacherattendance -table fields are(id t_adate t_amonth t_ayear t_attendance )
id t_adate t_amonth t_ayear t_attendance
1 15 07 2015 1
2 15 07 2015 1
3 15 07 2015 1
4 15 07 2015 1
5 15 07 2015 1
6 15 07 2015 1
7 15 07 2015 1
8 15 07 2015 1
9 15 07 2015 1
10 15 07 2015 1
i have 10 teachers and iam enter all attendances are 1, insert into database t_attendance is 1 for all 10 rows.
when im enter submit button values go to database and redirect to another page ,before check all t_attendance is 1 or not .
1st condition
if its all 1 go to home page.
id t_adate t_amonth t_ayear t_attendance
1 15 07 2015 1
2 15 07 2015 1
3 15 07 2015 1
4 15 07 2015 0
5 15 07 2015 1
6 15 07 2015 1
7 15 07 2015 0
8 15 07 2015 1
9 15 07 2015 1
10 15 07 2015 1
2nd condition
if any t_attendance value is 0 then go to attendance page.
how to check these 2 conditions.
iam us its controller code
foreach ($teachers as $teacher){
$teacheratt = new WysTeacherattendance();
$teacheratt->t_auserid = $teacher->user_id;
$teacheratt->t_adate=$date_exploded[0];
$teacheratt->t_amonth=$date_exploded[1];
$teacheratt->t_ayear=$date_exploded[2];
$teacheratt->t_attendance=Input::get($teacher->user_id);
$teacheratt ->save();
}
if($users = DB::table('wys_teacherattendances')
->where('t_adate',$date_exploded[0])
->whereIn('t_attendance', array(1))->get())
{return Redirect::route('GetTeachersearchAttendence')
->with('success',' teacher exist');
}
if($users = DB::table('wys_teacherattendances')
->where('t_adate',$date_exploded[0])
->where('t_attendance', '=',0)->get())
{return Redirect::route('AddTeacherabsentReason',$date_exploded[0])
->with('success',' teacher exist');
}
}`
but only work this condition `if($users = DB::table('wys_teacherattendances')
->where('t_adate',$date_exploded[0])
->whereIn('t_attendance', array(1))->get())
{return Redirect::route('GetTeachersearchAttendence')
->with('success',' teacher exist');
}
how solve it??
try this
if($users == DB::table('wys_teacherattendances')
->where('t_adate',$date_exploded[0])
->whereIn('t_attendance', array(1))->get())
{return Redirect::route('GetTeachersearchAttendence')
->with('success',' teacher exist');
}
for compare result, you must use ==, not = (= assigning value, not checked the value)
I think you must change all "=" you have typed with "=="
I only give the idea
You can check the number of that teacher
$teacher_number = "SELECT COUNT(teacher) from teacher"
You can check the number of that attendance
$attendance = "SELECT COUNT(attendance) from attendance where
attendance = 1 and date = yourdate"
if $teacher_number == $attendance
redirect home.page
else if $teacher_number > $attendance
redirect attendance.page
Related
I am trying to find the last entry for the previous years quarter.
All I can access is year i.e 2021 and quarter i.e 1
Here is the data in my database:
id
name
start
end
16
April 2021
2021-04-01
2021-04-30
15
March 2021
2021-03-01
2021-03-31
14
February 2021
2021-02-01
2021-02-28
57
November 2020
2020-11-01
2020-11-30
55
October 2020
2020-10-01
2020-10-31
29
September 2020
2020-09-01
2020-09-30
27
July 2020
2020-07-01
2020-07-31
24
April 2020
2020-04-01
2020-04-30
23
March 2020
2020-03-01
2020-03-31
22
February 2020
2020-02-01
2020-02-29
21
January 2020
2020-01-01
2020-01-31
Using the MySQL quarter function I can get it to print out the quarter as an integer in another column:
SET #given_year = 2021;
SET #given_quarter = 1;
SELECT
id, name, start, end, QUARTER(end) as "Q"
FROM
submissions
id
name
start
end
Q
16
April 2021
2021-04-01
2021-04-30
2
15
March 2021
2021-03-01
2021-03-31
1
14
February 2021
2021-02-01
2021-02-28
1
57
November 2020
2020-11-01
2020-11-30
4
55
October 2020
2020-10-01
2020-10-31
4
29
September 2020
2020-09-01
2020-09-30
3
27
July 2020
2020-07-01
2020-07-31
3
24
April 2020
2020-04-01
2020-04-30
2
23
March 2020
2020-03-01
2020-03-31
1
22
February 2020
2020-02-01
2020-02-29
1
21
January 2020
2020-01-01
2020-01-31
1
I tried using WHERE and LIKE but it is returning 0 rows:
SELECT * FROM (
SELECT
id, name, start, end, QUARTER(end) as "Q"
FROM
submissions as s
) AS vs
WHERE
vs.end
LIKE
#given_year
AND
vs.Q < #given_quarter
I also need to account for the possibility that there may be no rows this year and I need to find the previous year.
For example with these two rows, if I was passed the year 2021 and quarter 1 I would need to return November of the previous year and a different quarter.
id
name
start
end
Q
14
February
2021
2021-02-01
2021-02-28
57
November
2020
2020-11-01
2020-11-30
If I understand correctly, you want all the rows from the quarter in the data before a given quarter. You can filter and use dense_rank():
select s.*
from (select s.*,
dense_rank() over (order by year(start) desc, quarter(start) desc) as seqnum
from submissions s
where year(start) < #given_year or
(year(start) = #given_year and quarter(start) < #given_quarter)
) s
where seqnum = 1;
The above returns all rows from the previous quarter (which is what I thought you wanted). If you want only one row:
select s.*
from submissions s
where year(start) < #given_year or
(year(start) = #given_year and quarter(start) < #given_quarter)
order by start desc
limit 1;
I have combination of domain and month with their total orders in corresponding month. I would like to impute missing combination with 0 values. What's the least expensive aggregation commands that can be used in Pyspark to achieve this ?
I have following input table:
domain month year total_orders
google.com 01 2017 20
yahoo.com 02 2017 30
google.com 03 2017 30
yahoo.com 03 2017 40
a.com 04 2017 50
a.com 05 2017 50
a.com 06 2017 50
Expected Output:
domain month year total_orders
google.com 01 2017 20
yahoo.com 02 2017 30
google.com 03 2017 30
yahoo.com 03 2017 40
a.com 04 2017 50
a.com 05 2017 50
a.com 06 2017 50
google.com 02 2017 0
google.com 04 2017 0
yahoo.com 04 2017 0
google.com 05 2017 0
yahoo.com 05 2017 0
google.com 06 2017 0
yahoo.com 06 2017 0
Here Expected order of output does not really matter.
The simplest method is to combine all months and years for each domain:
select my.year, my.month, d.domain, coalesce(t.total_orders, 0) as total_orders
from (select distinct month, year from input) my cross join
(select distinct domain from input) d left join
t
on t.month = my.month and t.year = my.year and t.domain = d.domain;
Note: This assumes that each year/month combination occurs at least once, somewhere in the data.
Getting values within a range is a pain because you have split the date into multiple columns. Let me assume the years are all the same, as in your example:
select my.year, my.month, d.domain, coalesce(t.total_orders, 0) as total_orders
from (select distinct month, year from input) my join
(select domain, min(month) as min_month, max(month) as max_month
from input
) d
on my.month >= d.min_month and my.month <= d.max_month left join
t
on t.month = my.month and t.year = my.year and t.domain = d.domain
i have 2 tables : dt_user and dt_invoice.
**dt_members :**
id firstname
3 Salim
5 Sara
8 Julie
**dt_invoice**
user_id amount_ht period month year
3 4950 04 2018 04 2018
3 7200 10 2018 10 2018
8 11000 10 2018 10 2018
8 5500 11 2018 11 2018
3 6750 11 2018 11 2018
3 8700 12 2018 12 2018
3 8800 01 2019 01 2019
8 7500 01 2019 01 2019
3 4950 02 2019 02 2019
3 7550 03 2019 03 2019
I want to create a query joining the two table, but i want to show each user_id for PERIOD that there is in table dt_invoice.
**Expected results :**
user_id amount_ht period month year
3 4950 04 2018 04 2018
5 0 04 2018 04 2018 //non-existent record in dt_invoice
8 0 04 2018 04 2018 //non-existent record in dt_invoice
3 7200 10 2018 10 2018
5 0 10 2018 10 2018 //non-existent record in dt_invoice
8 11000 10 2018 10 2018
8 5500 11 2018 11 2018
5 0 11 2018 11 2018 //etc ...
3 6750 11 2018 11 2018
3 8700 12 2018 12 2018
5 0 12 2018 12 2018
8 0 12 2018 12 2018
3 8800 01 2019 01 2019
5 0 01 2019 01 2019
8 7500 01 2019 01 2019
3 4950 02 2019 02 2019
5 0 02 2019 02 2018
8 0 02 2019 02 2018
3 7550 03 2019 03 2019
5 0 03 2019 03 2018
8 0 03 2019 03 2018
Thanks in advance for your help, i'm totally stuck ..
SQL datas available here : https://rextester.com/live/LBSEY76360
also in sqlfiddle : http://sqlfiddle.com/#!9/728af3/1
Use a cross join to generate the rows and left join to bring in the values:
select m.user_id, p.period, p.month, p.year,
coalesce(t.amount_ht, 0) as amount_ht
from dt_members m cross join
(select distinct period, month, year from dt_invoice) p left join
dt_invoice t
on t.user_id = m.id and t.period = p.period;
Maybe this would help.
SELECT user_id, amount_ht, period, month, year
FROM dt_invoice
LEFT JOIN dt_members ON user_id = id
I have two mysql tables
suppose table one name 'marks'
no A B C D
1 10 05 01 04
2 08 07 10 05
3 09 05 07 10
4 07 05 04 10
5 04 07 06 09
6 05 09 07 07
7 09 05 10 06
8 09 06 06 08
9 08 06 10 07
10 08 07 04 06
suppose table two name 'results'
in second table I want to put total marks and average marks based on above table.(import data from 'marks' table,process it and save it in 'results' table)
So once it filled it must be like this.
I want add column A,B,C,D in 'marks' table and put total value in column 'Total' in table 'results' and average by dividing 'Total' column by 4.
no Total Average
1 20 5.00
2 30 7.50
3 31 7.75
4 26 6.50
5 26 6.50
6 28 7.00
7 30 7.50
8 29 7.25
9 31 7.75
10 25 6.25
So how can I fill the 'result' table using mysql query?
Is it possible to do in mysql?
Thank you
Try something like:
INSERT INTO result (no, total, average)
SELECT no, A+B+C+D, (A+B+C+D)/4
FROM marks
I have the following tables:
http://sqlfiddle.com/#!2/1e991/1
But I have a problem! The output of my query is:
DATE SLOT sum(SUCCESSFUL) SUCCESSFUL PERCENTAGE OTA_NAME USERS_SI
July, 02 2013 00:00:00+0000 2 120 120 41.6667 campana 2 50
July, 02 2013 00:00:00+0000 1 200 200 25 campana 2 50
July, 02 2013 00:00:00+0000 1 150 150 53.3333 campana 3 80
July, 01 2013 00:00:00+0000 2 100 100 20 campana 1 20
July, 01 2013 00:00:00+0000 3 440 440 4.5455 campana 1 20
July, 01 2013 00:00:00+0000 1 700 700 2.8571 campana 1 20
And I need a sum of successful with the same date and campaign, for example, I have in July 1 with campaign 1 three rows, then I need sum the successful of the three rows, and with campaign 2 two rows, then I need sum the successful of the two rows, and with campaign 3 one rows, then I need sum the successful of the one row that is the same.
And finally the percentage is the division between sum(SUCCESSFUL) and USERS_SI
The output that I need is:
DATE SLOT sum(SUCCESSFUL) SUCCESSFUL PERCENTAGE OTA_NAME USERS_SI
July, 02 2013 00:00:00+0000 2 320 120 41.6667 campana 2 50
July, 02 2013 00:00:00+0000 1 320 200 25 campana 2 50
July, 02 2013 00:00:00+0000 1 150 150 53.3333 campana 3 80
July, 01 2013 00:00:00+0000 2 1240 100 20 campana 1 20
July, 01 2013 00:00:00+0000 3 1240 440 4.5455 campana 1 20
July, 01 2013 00:00:00+0000 1 1240 700 2.8571 campana 1 20
Can you help me?
sqlfiddle here
SELECT other.date AS date,
other.slot,
other.successful,
calc.sum_successful,
max((case when (rule.tree_si = dms.tree) then dms.numberResponses end))/successful AS percentage,
other.name AS ota_name,
other.successful AS successful,
max((case when (rule.tree_si = dms.tree) then dms.numberResponses end)) AS users_si
FROM aca_ota_other other
join aca_dms_rules rule on other.name = rule.ota_name
join aca_dms dms on dms.date = other.date and rule.tree_si = dms.tree
join (SELECT name, sum(successful) as sum_successful FROM aca_ota_other GROUP BY name) as calc on other.name = calc.name
GROUP BY
other.date,
other.name,
other.successful
ORDER BY other.date desc
I'm not sure but if i understood well, you need something like this:
I'm sorry, I've made some little changes in your query.
SELECT other.date date,
other.slot,
other.name ota_name,
sum(successful) successful,
dms.numberResponses users_si,
SUM(successful)/dms.numberResponses AS percentage
FROM aca_ota_other other
JOIN aca_dms_rules rule ON other.name=rule.ota_name
JOIN aca_dms dms ON dms.date=other.date AND rule.tree_si=dms.tree
GROUP BY other.date,
other.name
ORDER BY other.date DESC
http://sqlfiddle.com/#!2/1e991/22