I have a table with numeric data that i need make diferent combinations itself.
For example:
| A |
|---|
| 1 |
| 2 |
| 3 |
| 4 |
I need to combine this single column to get the next result:
| A | B | C | D |
| - | - | - | - |
| 1 | | | |
| 1 | 2 | | |
| 1 | 2 | 3 | |
| 1 | 2 | 3 | 4 |
| 1 | 2 | | 4 |
| 1 | | 3 | |
| 1 | | 3 | 4 |
| 1 | | | 4 |
| | 2 | | |
| | 2 | 3 | |
| | 2 | 3 | 4 |
| | 2 | | 4 |
| | | 3 | |
| | | 3 | 4 |
| | | | 4 |
At the end of the table, i have to create a column with the Count of every column that has data and another column that contains the sums of number of each columns.
Maybe it sound very difficult or impossible, but I haven't a way to make it work.
I have try to "Cross Join" from SQL but didn't got the expected result.
Help!
In this case, you can solve this by counting in binary ending with the digits being the number of numbers in the set. etc. the starting set 2568 would end with 1111. this binary number would decide if you show that number in each row. Heres a table of how it would work.
| A |
|---|
| 2 |
| 5 |
| 6 |
| 8 |
A
B
C
D
Binary
Row number
8
0001
1
6
0010
2
6
8
0011
3
5
0100
4
5
8
0101
5
5
6
0110
6
5
6
8
0111
7
2
1000
8
2
8
1001
9
2
6
1010
10
2
6
8
1011
11
2
5
1100
12
2
5
8
1101
13
2
5
6
1110
14
2
5
6
8
1111
15
I want to select data from say 2nd week of a particular month and I have a column containing dates, then, how should I go with it.
I have data as such -
+-----+---------------------+-------------+
| id | date | daily_cases |
+-----+---------------------+-------------+
| 1 | 2020-01-30 00:00:00 | 1 |
| 2 | 2020-01-31 00:00:00 | 0 |
| 3 | 2020-02-01 00:00:00 | 0 |
| 4 | 2020-02-02 00:00:00 | 1 |
| 5 | 2020-02-03 00:00:00 | 1 |
| 6 | 2020-02-04 00:00:00 | 0 |
| 7 | 2020-02-05 00:00:00 | 0 |
| 8 | 2020-02-06 00:00:00 | 0 |
| 9 | 2020-02-07 00:00:00 | 0 |
| 10 | 2020-02-08 00:00:00 | 0 |
Need some help in getting a collection, using Laravel Eloquent, from a table but ordered by the parent_id to achieve, as an example, the following hierarchy:
Africa
Eastern Africa
Middle Africa
Northern Africa
Asia
Central Asia
Eastern Asia
(...) etc.
The below table is what I have and it's ordered by parent_id only.
What I'm trying to achieve is the parent > children ordering. Thanks in advance for any help.
+----+---------------------------------+-----------+
| id | region_common_name | parent_id |
+----+---------------------------------+-----------+
| 1 | Global | 0 |
| 2 | Africa | 1 |
| 14 | Americas | 1 |
| 33 | Antartica | 1 |
| 3 | Asia | 1 |
| 6 | Australasia | 1 |
| 4 | Europe | 1 |
| 10 | Eastern Africa | 2 |
| 11 | Middle Africa | 2 |
| 8 | Northern Africa | 2 |
| 12 | Southern Africa | 2 |
| 9 | Sub-Saharan Africa | 2 |
| 13 | Western Africa | 2 |
| 20 | Central Asia | 3 |
| 21 | Eastern Asia | 3 |
| 22 | South-eastern Asia | 3 |
| 23 | Southern Asia | 3 |
| 24 | Western Asia | 3 |
| 25 | Eastern Europe | 4 |
| 26 | Northern Europe | 4 |
| 27 | Southern Europe | 4 |
| 28 | Western Europe | 4 |
| 16 | Caribbean | 5 |
| 17 | Central America | 5 |
| 15 | Latin America and the Caribbean | 5 |
| 19 | Northern America | 5 |
| 29 | Australia and New Zealand | 6 |
| 30 | Melanesia | 6 |
| 31 | Micronesia | 6 |
| 32 | Polynesia | 6 |
| 5 | North America | 14 |
| 18 | South America | 14 |
| 7 | Southern America | 18 |
+----+---------------------------------+-----------+
You can order by multiple conditions but have to join on yourself.
Example in SQL
SELECT rp.region_common_name parent_name, r.region_common_name FROM regions r
INNER JOIN regions rp ON r.parent_id = rp.id
WHERE r.parent_id != 1 AND r.parent_id != 0
ORDER BY rp.region_common_name ACS, r.region_common_name ASC
So your result will look like this:
+---------------------------------+---------------------------------+
| parent_name | region_common_name |
+---------------------------------+---------------------------------+
| Africa | Eastern Africa |
| Africa | Middle Africa |
| Americas | North America |
| Americas | South America |
+---------------------------------+---------------------------------+
In eloquent you can use the QueryBuilder to generate your query.
It will look like this:
DB::table('regions as r')
->join('regions as rp', 'r.parent_id', '=', 'rp.id')
->where('r.parent_id', '!=', '0')
->where('r.parent_id', '!=', '1')
->orderBy('rp.region_common_name', 'asc')
->orderBy('r.region_common_name', 'asc')
->select('rp.region_common_name as parent_name', 'r.region_common_name as name');
Is there a way to calculate Custom Week numbers that start from a user's first Transaction Date onwards? The Users (emailId) and TransDate columns may not be in a sorted condition as shown below:
e.g.
+------+-------------+---------------------+
| WkNo | TransDate | emailId |
+------+-------------+---------------------+
| 1 | 2018-Aug-30 | moz.shea#abc.com |
| 1 | 2018-Aug-30 | moz.shea#abc.com |
| 10 | 2018-Nov-07 | moz.shea#abc.com |
| 1 | 2018-Aug-09 | zabi.prado#abc.com |
| 1 | 2018-Aug-09 | zabi.prado#abc.com |
| 6 | 2018-Sep-20 | zabi.prado#abc.com |
| 15 | 2018-Nov-23 | zabi.prado#abc.com |
| 21 | 2018-Dec-31 | zabi.prado#abc.com |
| 1 | 2018-Aug-20 | silo.whitte#abc.com |
| 5 | 2018-Sep-23 | silo.whitte#abc.com |
| 7 | 2018-10-11 | silo.whitte#abc.com |
| 7 | 2018-10-11 | silo.whitte#abc.com |
| 8 | 2018-Oct-14 | silo.whitte#abc.com |
| 9 | 2018-Oct-19 | silo.whitte#abc.com |
| 1 | 2018-Jul-01 | pablo.gucci#abc.com |
| 6 | 2018-Aug-10 | pablo.gucci#abc.com |
| 13 | 2018-Oct-03 | pablo.gucci#abc.com |
+------+-------------+---------------------+
I wrote the following formula using FILTER function that then supplies the filtered dates per user to the DATEDIF function. However, i am not getting the desired result as shown above.
=ARRAYFORMULA(if(B2:B="","",1 + round(DATEDIF(min(sort(FILTER(B2:B,C2:C=C2:C),1,true)),sort(FILTER(B2:B,C2:C=C2:C),1,true),"D")/7)))
EDIT:
Formula Result:
1
7
7
7
8
10
10
13
13
14
16
16
16
17
19
22
27
Also removed SORT from above formula:
=ARRAYFORMULA(if(B2:B="","",1 + round(DATEDIF(min(sort(FILTER(B2:B,C2:C=C2:C),1,true)),FILTER(B2:B,C2:C=C2:C),"D")/7)))
Formula Result:
10
10
19
7
7
13
22
27
8
13
16
16
16
17
1
7
14
Both seem to work, but give unexpected results as MIN is evaluating to a single date 2018-Jul-01 instead of an Array of Minimum dates per user. Where am i going wrong?
Did you try using the MINIFS() function ?
EG with the following
Dates in cells B2:B10
Emails in Cells C2:C10
The formula in cell A2 would give the earliest date for the email address in Cell C2
=MINIFS($B$2:$B$10, $C2:$C10, "="&C2)
You should be able to use this in your formula to calculate the number of weeks
For those who might face a similar challenge, here is the answer:
=ARRAYFORMULA(IF(B2:B="","",ROUND((B2:B-VLOOKUP(C2:C,SORT({C2:C,B2:B},2,1),2,0))/7)+1))
The idea is to do a Vlookup on column C, passing it a switched and sorted range of dates in ascending order. These first dates are then deducted from the B column dates, to get the desired result ie. either days or weeks.
One can remove the +1 as i used it just to display the starting week as 1 instead of 0. So the result may differ slightly. But without +1, the result is accurate, especially if you are doing a Cohort.
0
0
10
0
0
6
15
21
0
5
7
7
8
9
0
6
13
As a check, i removed division by 7 and +1, then checked the days, which are correct.
0
0
69
0
0
42
106
144
0
34
52
52
55
60
0
40
94
Hope this helps.
I have created a bus transit application for a city in windows phone 8. I have stored all my routes and bus stops in a separate table in the database.
My bus stop table contains:
stop_id | stop_name | latitude | longitude | status | alias_name
---------------------------------------------------------------------------------------
1736 | Atlas Company | 18.629243 | 73.833814 | Active | Centurenca Corner
1737 | Atlas company | 18.629243 | 73.833814 | Active |
681 | Atma Anand Dhyan Kendra | 18.600349 | 73.926251 | InActive |
My Routes Table contains
bus_id | bus_no | bus_source | bus_destination | days_of_week | total_distance estimated_time | source_stop_names | destination_stop_names | total_stops | source_trip_time | destination_trip_time | bus_status
source_stop_names contains
-----------------
1 | Swargate
2 | Parvati payatha
3 | Dandekar pul
4 | Pan mala Sinhgad Road
5 | Jal Shuddhikarn Kendra Sinhgad Road
6 | Ganesh mala
7 | Vitbhatti Sinhgad Road
8 | Vitthalwadi jakat naka
9 | Jaydeo nagar
10 | Rajaram pul
11 | Vitthalwadi Mandir Hingne
12 | Hingne rasta
13 | Anand nagar singhgad rd
14 | Manik Bag
15 | Indian hum company
16 | Wadgaon phata
17 | Patil colony
18 | Dhayari phata
19 | Sanas Vidyalaya
20 | Dangat wasti
21 | Gar mala
22 | Dhayarai gaon
23 | Raykar wasti
24 | Poultry farm singhgad road
25 | Dhayarigaon shala
26 | Chavan mala
27 | DSK Vishwa
I want to find the shortest path between two bus stops not connected by a bus route, and show the number of routes and buses the user has to take while travelling from one point to another, like google maps does.
I have used default map control in windows phone 8.