## Why is this code not working with distinct

Why is this code not working it always give me multiple filds at the lf_work_task_info :/

FROM ( SELECT DISTINCT owt.lf_work_task_info, owt.order_id, owt.loading_unit_id, ogia_sub.group_order_id AS out_del_ord_id FROM klassx.loading_unit lou JOIN klassx.orders ord_classic ON ( ord_classic.loading_unit_id = lou.loading_unit_id AND ord_classic.order_type_id = wmw_type.ort_classic ) JOIN klassx.order_work_task owt ON ( owt.order_id = ord_classic.order_id OR owt.loading_unit_id = lou.loading_unit_id ) JOIN klassx.v_order_group_item_all ogia_cla ON ( ogia_cla.order_id = ord_classic.order_id AND ogia_cla.group_type_id = wmw_type.ogt_master_orders ) JOIN klassx.v_order_group_item_all ogia_sub ON ( ogia_cla.group_order_id = ogia_sub.order_id AND ogia_sub.group_type_id = wmw_type.ogt_delivery_order ) JOIN klassx.orders ord_classic ON ( owt.order_id = ord_classic.order_id ) WHERE owt.work_task_type_id = wmw_type.wtt_vas AND owt.work_task_status_id = wmw_type.wts_open AND owt.work_task_reason_id = wmw_type.wtr_vas_dispatch AND lou.deleted = util_bool.no ) disp_vas_txt JOIN klassx.order_group org ON ( org.order_id = disp_vas_txt.out_del_ord_id ) —outbound_del GROUP BY org.order_id, disp_vas_txt.lf_work_task_info ;

## With repetition, no order. Probability of drawing atleast 18 distinct balls, when there are 20 different balls and one has 50 draws?

I came up with this today, however I could not figure out a solution to this problem. Say, you have a pool of 20 different balls. Therefore, the probability of drawing one of the balls is equal to drawing any other. Also, you have 50 draws. Our variables so far are: n=20 (# of balls) k=50 (# of moves) p=5% (% of a certain ball). Obviously, the number of combinations in this problem is: nCr(20+50-1;50). Additionally, in the a-th draw the probability of drawing a yet undrawn ball is: (1-p)^a. Could you please explain to me what the solution to this problem is and how it works? I am looking forward to reading your answers and thanks in advance.

## Suffix array and counting distinct substrings of specific length

I am trying to use the suffix array, and the LCP array to count all distinct substrings of a specified length.

I started with the algorithm for counting ALL distinct substrings. I solved it after this explanation: https://www.geeksforgeeks.org/count-distinct-substrings-string-using-suffix-array/ . The problem right now is that I can’t figure out how to only count the substrings of my given length, and not all possibilities.

I also computed the array which tells me how many suffixes are lexicographically smaller than suffix_array[i].

Any ideas what I could use to do it?

## Given an array of sum and an array how can to find if all the sums are possible using distinct elements of array?

example:

if we have array of int as 1 2 3 and sum array is given 3,3 we can form this sum as {1,2} and {3} if the sum array is 5 3 we can not create the sum array, we can for {2,3} but not enough items to form the sum 3.

Can someone help me to understand which algorithm can be used to solve the problem.

## Select Distinct em apenas uma das tabelas

Tenho as seguintes tabelas separadas, A e B que estou colocando uma ao lado da outra para facilitar:

+--------------+------------+-------------+ |ID Relacional |     A      |      B      | +--------------+------------+-------------+ | 35           | 30         | 28          | | 20           | 10         | 4           | | 20           | 10         | 5           | +--------------+------------+-------------+ 

Preciso criar um código que, divida o valor de B pelo de A.

Exemplo: 1ª linha: 28/30.

Mas, quando o ID Relacional for repetido, necessito dividir apenas um valor de A pela soma do valor de B.

Exemplo: 2ª e 3ª linha: 10 / (5 + 4)

Meu código atual:

select sum(A.valorA) as ColunaA, sum(B.valorB) as ColunaB, sum(B.valorB) /sum(A.valorA) as Resultado  from tableA A, tableB B where A.id = B.id group by ... order by ... 

A tabela resultante é

+--------------+------------+-------------+ |  ColunaA     |  ColunaB   |   Resultado | +--------------+------------+-------------+ | 30           | 28         | 0.93        | | 10           | 4          | 0.45 (9/20) | | 10           | 5          |             | +--------------+------------+-------------+ 

## Get all possible subsets from a set of distinct integers using OOP

An assignment at school required me to write a program for this task:

1. Create a class and define two methods in the class.
2. Method f1 is used to pass an empty list and the sorted list is taken from the user to method f2.
3. Method f2 is used to compute all possible subsets of the list.
4. Then the result is returned from the function and printed.
5. Exit

Here is my solution to this task, using Python:

class sub:       def f1(self, s1):           return self.f2([], sorted(s1))        def f2(self, current, s1):           if s1:               return self.f2(current, s1[1:]) + self.f2(current + [s1[0]], s1[1:])           return [current]   a = [] n = int(input("Enter number of elements of list: ")) for i in range(0,n):     b = int(input("Enter element: "))     a.append(b) print ("Subsets: ") print (sub().f1(a)) 

NOTE – Method f2 is a recursive function.

Here are some example outputs:

Enter number of elements of list: 2 Enter element: 4 Enter element: 5 Subsets:  [[], [5], [4], [4, 5]]  Enter number of elements of list: 4 Enter element: 3 Enter element: 5 Enter element: 7 Enter element: 28 Subsets:  [[], [28], [7], [7, 28], [5], [5, 28], [5, 7], [5, 7, 28], [3], [3, 28], [3, 7], [3, 7, 28], [3, 5], [3, 5, 28], [3, 5, 7], [3, 5, 7, 28] 

So, I would like to know whether I could make this program shorter and more efficient.

Any help would be highly appreciated.

## Combinatorics: Distribution of red, blue and green balls into distinct bins

Assume that there are three different kinds of balls, R red balls, B blue balls, and G green balls. How many ways are there to distribute the balls into N different bins so that no bin is empty and a bin can have at most one ball of the same color? Here,

1) R,B,G<=N (no color should have more than N balls as we have the condition that at most one balls of the same color in a bin and all balls needs to be placed)

and

2) R+B+G>=N (This is due to the fact that no bin is empty).

## The number of ways to place distinct balls in identical bins

Count the number of ways to place 6 distinct balls in 4 identical bins

I tried to use “Stirling number” for this problem.

S(n,k) = S(n-1,k-1) + k*S(n-1,k) if 1 < k < n

S(n-1,k-1) = $$\binom{n+k-1}{k-1} = \binom{9}{3} = \frac{9!}{3!*6!} = 84$$

k*S(n-1,k) = 4 * $$\binom{n-1}{k} = \binom{5}{4} = \frac{5!}{4!} = 5$$ = 20

84 + 20 = 104

DECLARE @EmployeePayrollDataTable AS TABLE (EmployeeId int,LegalOverTime int,ExtraOverTime int,ToatalOverTime int,OK int,LateDays int,         AbsentDays int, LeaveDays int, HolidayOffdays int,BasicPay decimal,GrossPay decimal,HouseRent decimal,MedicalFoodTransportCost decimal,         BasicPayRate decimal,GrossPayRate decimal,OverTimeRate float,AttendanceBonus decimal,StampDeduction decimal);  DECLARE @EmployeePayrollTable AS TABLE (EmployeeId int,BasicSalary decimal,HouseRent decimal,MedicalFoodTransportCost decimal,GrossSalary decimal, TotalPresents int,         HolidayOffdays int, LeaveDays int,AbsentDays int, TotalDeduction decimal, TotalSalary decimal, AttendanceBonus decimal, OvertimeHours int, OvertimeRate float,         OvertimeAmount decimal, StampCharge decimal, FinalSalary decimal)  INSERT INTO @EmployeePayrollDataTable SELECT A.EmployeeId,A.LegalOverTime,A.ExtraOverTime,A.ToatalOverTime,A.OK,A.LateDays,A.AbsentDays,A.LeaveDays,A.HolidayOffdays,    B.BasicPay,B.GrossPay,B.HouseRent,B.MedicalFoodTransportCost,B.BasicPayRate,B.GrossPayRate,B.OverTimeRate,B.AttendanceBonus,B.StampDeduction FROM          (SELECT TT.EmployeeId,          SUM(TT.LegalOverTime) AS LegalOverTime,         SUM(TT.ExtraOverTime) AS ExtraOverTime,          SUM(TT.LegalOverTime)+SUM(TT.ExtraOverTime) AS ToatalOverTime,         ISNULL(COUNT(OK), 0 ) OK,         ISNULL(COUNT(LateDays), 0 ) LateDays,         ISNULL(COUNT(AbsentDays), 0 ) AbsentDays,         ISNULL(COUNT(LeaveDays), 0 ) LeaveDays,         ISNULL(COUNT(HolidayOffdays), 0 ) HolidayOffdays FROM (SELECT HAH.EmployeeId,         CASE WHEN HAH.AttendanceStatus!=5 OR HAH.AttendanceStatus!=6 THEN                  CASE WHEN HAH.PayableOverTime<=2 THEN HAH.PayableOverTime                 WHEN HAH.PayableOverTime>2 THEN 2                 ELSE 0                 END         ELSE 0         END AS LegalOverTime,          CASE WHEN HAH.AttendanceStatus!=5 OR HAH.AttendanceStatus!=6 THEN                  CASE WHEN HAH.PayableOverTime<=2 THEN 0                 WHEN HAH.PayableOverTime>2 THEN HAH.PayableOverTime-2                 ELSE 0                 END         ELSE HAH.PayableOverTime         END AS ExtraOverTime,         CASE WHEN          (AttendanceStatus=1 and HAH.[Status]=1) THEN AttendanceStatus END AS OK,         CASE WHEN          (AttendanceStatus=2 and HAH.[Status]=1) THEN AttendanceStatus END AS LateDays,         CASE WHEN          (AttendanceStatus=3 and HAH.[Status]=1) THEN AttendanceStatus END AS AbsentDays,         CASE WHEN          (AttendanceStatus=4 and HAH.[Status]=1) THEN AttendanceStatus END AS LeaveDays,         CASE WHEN          ((AttendanceStatus=5 or AttendanceStatus=6) and HAH.[Status]=1) THEN AttendanceStatus END AS HolidayOffdays  FROM HRMS_Attendance_History as HAH JOIN HRMS_Employee HE on HAH.EmployeeId=HE.ID WHERE HE.Present_Status=1 and CAST(HE.Joining_Date as Date)<='2019-04-01' and CAST([Date] as Date)>='2019-04-01' and CAST([Date] as Date)<='2019-04-30') TT GROUP BY TT.EmployeeId)  A JOIN  (SELECT T.EmployeeId, ISNULL(SUM(BasicPay), 0 ) BasicPay, ISNULL(SUM(GrossPay), 0 ) GrossPay, ISNULL(SUM(HouseRent), 0 ) HouseRent, ISNULL(SUM(MedicalFoodTransportCost), 0 ) MedicalFoodTransportCost, ISNULL(SUM(BasicPay)/30, 0 ) BasicPayRate, ISNULL(SUM(GrossPay)/30, 0 ) GrossPayRate, ISNULL(SUM(OverTimeRate), 0 ) OverTimeRate, ISNULL(SUM(AttendanceBonus), 0 ) AttendanceBonus, ISNULL(SUM(StampDeduction), 0 ) StampDeduction  FROM (SELECT EmployeeId, CASE WHEN  (Eod_RefFk=1 and er.[Status]=1) THEN ActualAmount END AS BasicPay, CASE WHEN  ((Eod_RefFk=1 or Eod_RefFk=2 or Eod_RefFk=3) and er.[Status]=1) THEN ActualAmount END AS GrossPay, CASE WHEN  (Eod_RefFk=2 and er.[Status]=1) THEN ActualAmount END AS HouseRent, CASE WHEN  (Eod_RefFk=3 and er.[Status]=1) THEN ActualAmount END AS MedicalFoodTransportCost, CASE WHEN  (Eod_RefFk=11 and er.[Status]=1) THEN ActualAmount END AS OverTimeRate, CASE WHEN  (Eod_RefFk=7 and er.[Status]=1) THEN ActualAmount END AS AttendanceBonus, CASE WHEN  (Eod_RefFk=12 and er.[Status]=1) THEN ActualAmount END AS StampDeduction FROM HRMS_EodRecord er JOIN HRMS_Employee e on er.EmployeeId=e.ID WHERE e.Present_Status=1 and CAST(e.Joining_Date as Date)<='2019-04-01') t  group by t.EmployeeId) B ON A.EmployeeId=B.EmployeeId   INSERT INTO @EmployeePayrollTable SELECT  EmployeeId,     BasicPay,     HouseRent,     MedicalFoodTransportCost,     GrossPay,     (OK+LateDays+LeaveDays+HolidayOffdays),     HolidayOffdays,     LeaveDays,     AbsentDays,     AbsentDays*BasicPayRate,     GrossPay-(AbsentDays*BasicPayRate),     CASE WHEN AbsentDays>0 or LeaveDays>0 or LateDays>2 THEN 0     ELSE AttendanceBonus END AS AttendanceBonus,     LegalOverTime,     OverTimeRate,     LegalOverTime*OverTimeRate,     StampDeduction,      CASE WHEN AbsentDays>0 or LeaveDays>0 or LateDays>2 THEN(LegalOverTime*OverTimeRate)+(GrossPay-(AbsentDays*BasicPayRate))-StampDeduction     ELSE (LegalOverTime*OverTimeRate)+(GrossPay-(AbsentDays*BasicPayRate)+AttendanceBonus)-StampDeduction END AS OvertimeAmount FROM @EmployeePayrollDataTable    select * from @EmployeePayrollTable