Finding continuous data from a table for months - mysql

I have a table which has month data in INT April=4, May=5 and so on. I want those records which have continuous data. My table is as follows. So if a record has discontinuous data, it should not be returned.
Continuous data means those records which having continuous four month. If records are there for 4,5,6,7 or 5,6,7,8 or 6,7,8,9 months then that record should come in result of a ID. If there records for a ID has 4,5,8,9 in month field this is discontinue data for me.
Initial query:
select ID, month from table1 where month in (4,5,6,7,8,9) group by month;
Initial Data:
PK ID month value
1 1 4 400
2 1 5 200
3 1 6 300
4 1 7 400
5 2 5 400
6 2 6 200
7 2 7 100
8 2 8 400
9 3 4 200
10 4 5 800
11 5 6 800
12 5 7 100
13 5 8 700
14 5 9 900
15 6 4 100
16 6 5 200
17 6 8 500
18 6 9 600
Result:
PK ID month value
1 1 4 400
2 1 5 200
3 1 6 300
4 1 7 400
5 2 5 400
6 2 6 200
7 2 7 100
8 2 8 400
11 5 6 800
12 5 7 100
13 5 8 700
14 5 9 900
My database is MySQL.
I have months from April(4) to Sept(9)

Try the below query this will work I hope!
SELECT ID, Month
FROM table1 WHERE month in (4,5,6,7,8,9)
GROUP BY ID, Month
HAVING count(ID)>3
kindly let me know this is working or not

Related

MYSQL I am trying to return a value where I need to compare one value against the minimum value for the same field when grouped against another field

Basically I am trying to calculate shots received in golf for various four balls, here is my data:-
DatePlayed PlayerID HCap Groups Hole01 Hole02 Hole03 Shots
----------------------------------------------------------------------
2018-11-10 001 15 2 7 3 6
2018-11-10 004 20 1 7 4 6
2018-11-10 025 20 2 7 4 5
2018-11-10 047 17 1 8 3 6
2018-11-10 048 20 2 8 4 6
2018-11-10 056 17 1 6 3 5
2018-11-10 087 18 1 7 3 5
I want to retrieve the above lines with an additional column which is to be calculated depending on the value in the group column, which is the players (Handicap - (the lowest handicap in the group)) x .75
I can achieve it in a group by but need to aggregate everything, is there a way I can return the value as above?, here is query that returns the value:
SELECT
PlayerID,
MIN(Handicap),
MIN(Hole01) AS Hole01,
MIN(Hole02) AS Hole02,
MIN(Hole03) AS Hole03,
MIN(CourseID) AS CourseID,
Groups,
ROUND(
MIN((Handicap -
(SELECT MIN(Handicap) FROM Results AS t
WHERE DatePlayed='2018-11-10 00:00:00' AND t.Groups=Results.Groups)) *.75))
AS Shots
FROM
Results
WHERE
Results.DatePlayed='2018=11=10 00:00:00'
GROUP BY
DatePlayed, Groups, PlayerID
.
PlayerID MIN(Handicap)Hole01 Hole02 Hole03 CourseID Groups Shots
-----------------------------------------------------------------
4 20 7 4 6 1 1 2
47 17 8 3 6 1 1 0
56 17 6 3 5 1 1 0
87 18 7 3 5 1 1 1
1 15 7 3 6 1 2 0
25 20 7 4 5 1 2 4
48 20 8 4 6 1 2 4
Sorry about any formatting really couldn't see how to get my table in here, any help will be much appreciated, I am using the latest mysql from ubuntu 18.04
Not an answer; too long for a comment...
First off, I happily know nothing about golf, so what follows might not be optimal, but it must, at least, be a step in the right direction...
A normalized schema might look something like this...
rounds
round_id DatePlayed PlayerID HCap Groups
1 2018-11-10 1 15 2
2 2018-11-10 4 20 1
round_detail
round_id hole shots
1 1 7
1 2 3
1 3 6
2 1 7
2 2 4
2 3 6
Hi Guys I have found the solution, basically I need to drop the MIN immediately after the ROUND of the equation and therefore it does not need a Group By.
SELECT
PlayerID,
Handicap,
Hole01,
Hole02,
Hole03,
CourseID,
Groups,
ROUND((Handicap -
(SELECT MIN(Handicap) FROM Results AS t
WHERE DatePlayed='2018-11-10 00:00:00'
AND t.Groups=Results.Groups))
*.75) AS Shots
FROM
Results
WHERE
Results.DatePlayed='2018=11=10 00:00:00'

order group_by in codeigniter

i have a table
id typesignal close open cont
1 4 150 300 2
2 3 20 40 1
3 2 50 75 15
4 1 15.2 30.8 5
5 1 200 225 8
6 6 200 500 8
7 7 10 20 4
8 8 9 12 2
9 9 5 8 3
10 5 40 50 4
11 4 5 8 9
12 5 4 2 3
13 8 5 4 0
i want to display the last row of each kind from the typesignal column.
$this->db->group_by('typesignal');
$query = $this->db->get('signals');
but I need the last row that was create i use
$this->db->group_by('typesignal');
$this->db->order_by("idSignal");
$query = $this->db->get('signals');
but its not working.
The expected output is: 13,12,11,9,8,7,6,5,3,2
i use this query
$this->db->group_by('typeSignal');
$this->db->select_max('idSignal');
$this->db->order_by("idSignal", "DESC");
$query = $this->db->get('signals');
return $query->result_array();
is working the secret is $this->db->select_max('idSignal');
Thanx for the help

Any Advice with Mysql Count

i have a t_class table in mySql,
in this table there are 3 columns, No, CLASS and POINT.
and there are approximately 5000 records in this table. i want the count of classes in this table.
No CLASS POINT
1 9 100
2 10 70
3 11 80
4 9 90
5 10 50
6 M 60
7 M 70
8 9 40
9 10 90
10 11 90
11 M 80
12 M 75
13 11 40
14 10 100
15 9 60
As you see there 4 types of classes - 9, 10, 11 and M.
But there is one problem. When it calculates the count of classes it must
summarize 11-th and M th classes. For example
CLASS COUNT
9 4
10 4
11 7
Thanks.
SELECT CLASS, COUNT(*) AS CNT
FROM table
GROUP BY CASE WHEN CLASS='M' THEN '11' ELSE CLASS END

Where are TFS Warehouse tables and how to access them directly?

I want to access warehouse of tfs to access the tables like
1)table that stores the code requests submitted,approved,rejected
2)table that stores which employee submitted the code or which team sumitted the code on
what date the code is submitted
3)table that stores th e bugs raised,bugs which are open,bugs closed,bugs priority(p0,p1,p2,p3) and some other details
i want the output in the form as below
date bugsClosed bugsOpen Reason
p0 p1 p2 p3 total p0 p1 p2 p3 total Active Fixed Postponed ByDesign ByRepro total
Jan 2 3 4 1 10 4 8 2 10 24 5 6 4 9 0 24
Feb 2 3 4 1 10 4 8 2 10 24 5 6 4 9 0 24
Mar 2 3 4 1 10 4 8 2 10 24 5 6 4 9 0 24
Apr 2 3 4 1 10 4 8 2 10 24 5 6 4 9 0 24
May 2 3 4 1 10 4 8 2 10 24 5 6 4 9 0 24
Jun 2 3 4 1 10 4 8 2 10 24 5 6 4 9 0 24
Thanks & Regards,
Srinivas P.
Start here... it will guide you to your answer.
http://msdn.microsoft.com/en-us/library/ms244696(v=vs.90).aspx
and here for a walk-through of the schema
http://msdn.microsoft.com/en-us/library/ms244711(v=VS.90).aspx
and here for writing custom reports on schema
http://msdn.microsoft.com/en-us/library/bb649552(v=VS.90).aspx

Selecting items from one column based on values in another.

I have the following data:
id1,id2
1 3
1 8
1 10
1 11
2 3
2 10
2 11
3 2
3 18
3 20
4 3
4 8
5 3
5 10
5 11
5 40
5 45
5 50
6 1
6 59
6 70
I won't get all id1 with id2 = 3,10,11.
For example, id1=4 only with id2=3, should not return.
The results should be
id1
1
2
5
SELECT distinct(ID1) FROM TBTEST WHERE ID2 IN(3,10,11)
SQL code
SELECT ID1,COUNT(ID2) FROM TBTEST
WHERE ID2 IN(3,10,11)
GROUP BY ID1
HAVING COUNT(ID2)=3
Is this what you need?