Click here to Skip to main content
15,887,135 members
Home / Discussions / Database
   

Database

 
QuestionHow to create linked server MySQL? Pin
Arun Sylvester J21-Nov-13 20:45
Arun Sylvester J21-Nov-13 20:45 
AnswerRe: How to create linked server MySQL? Pin
jschell22-Nov-13 9:50
jschell22-Nov-13 9:50 
QuestionSemicolon delimited lists in SQL Pin
.dan.g.21-Nov-13 13:12
professional.dan.g.21-Nov-13 13:12 
AnswerRe: Semicolon delimited lists in SQL Pin
Mycroft Holmes21-Nov-13 13:38
professionalMycroft Holmes21-Nov-13 13:38 
AnswerRe: Semicolon delimited lists in SQL Pin
PIEBALDconsult21-Nov-13 13:48
mvePIEBALDconsult21-Nov-13 13:48 
AnswerRe: Semicolon delimited lists in SQL Pin
Peter Leow21-Nov-13 13:58
professionalPeter Leow21-Nov-13 13:58 
GeneralRe: Semicolon delimited lists in SQL Pin
.dan.g.21-Nov-13 14:13
professional.dan.g.21-Nov-13 14:13 
Questionfind total money of parent node of tree according to a particular pattern Pin
jitendra raj20-Nov-13 5:54
jitendra raj20-Nov-13 5:54 
 hi friends actually i am working on a mlm project in which members are added in a tree pattern, and get the payment accordingly.

My table  structure is as follow:

        Id         ParentId        IsLeft           IsRight
         1          Null             Null             Null
         2           1                1               Null
         3           1               Null               1
         4           2                1               Null
         5           2               Null               1
         6           3                1               Null
         7           3               Null               1
         8           4                1               Null
         9           4               Null               1
         10          5                1               Null

the problem is that initially 1500$ are given to parent when two nodes are added to its left and one to his right(2:1) . and then 500$ for each pair.

My problem is to find the query which can return the total income of any given node.

enter image description here

According to figure node 1 must get 2500$ (1500+500+500) first 500$ is for node 4 and second 500$ is for node 3.

According to figure node 2 must get 1500$ because it has two nodes to its left and one node to its right this means a ratio of (2:1). and has no pairs

According to figure node 3 must get 0$ because it does not have any nodes in ratio(2:1)

one thing has to be kept in mind that 1500$ will be the first payment and then only the other pairs will be counted, and 1500$ will be given when node has ratio 2:1(two nodes on left and one on right) but no money when ratio is 1:2(one node on left and two on right)

I have found the query which will count all the pairs below a particular node and give receiving amount according to 500$, but the query has not been able to consider the first condition that is the 2:1 condition

        declare @ParentId as int
         set @ParentId=1

       create table #temp_table_name
        (
          ParentId varchar(30) null,
         )


      ;with Child as
       (
    select id,ParentId from tblTestingTree where id=@ParentId
    union all
    Select tblTestingTree.Id,tblTestingTree.parentId from tblTestingTree 
    inner join Child 
    on tblTestingTree.ParentId=Child.Id
       )

  insert into #temp_table_name
  select c.ParentId  from tblTestingTree T join Child c
  on c.Id=t.Id
  WHERE ISNULL(T.ParentId, 0) <> 0 and c.ParentId!=@ParentId
  group by c.ParentId
  having COUNT(c.ParentId)>1 

  select COUNT(*)*500 as totalmoney from #temp_table_name

  drop table #temp_table_name

AnswerRe: find total money of parent node of tree according to a particular pattern Pin
Mycroft Holmes20-Nov-13 19:25
professionalMycroft Holmes20-Nov-13 19:25 
GeneralRe: find total money of parent node of tree according to a particular pattern Pin
jitendra raj20-Nov-13 22:46
jitendra raj20-Nov-13 22:46 
GeneralRe: find total money of parent node of tree according to a particular pattern Pin
Mycroft Holmes21-Nov-13 1:35
professionalMycroft Holmes21-Nov-13 1:35 
AnswerRe: find total money of parent node of tree according to a particular pattern Pin
Jörgen Andersson21-Nov-13 1:37
professionalJörgen Andersson21-Nov-13 1:37 
GeneralRe: find total money of parent node of tree according to a particular pattern Pin
jschell21-Nov-13 8:30
jschell21-Nov-13 8:30 
QuestionDynamic Filter Stored Procedure Pin
Commish1319-Nov-13 6:38
professionalCommish1319-Nov-13 6:38 
AnswerRe: Dynamic Filter Stored Procedure Pin
Mycroft Holmes19-Nov-13 12:02
professionalMycroft Holmes19-Nov-13 12:02 
Questionhow to write MAX query Pin
spanner2118-Nov-13 20:15
spanner2118-Nov-13 20:15 
AnswerRe: how to write MAX query Pin
Wayne Gaylard18-Nov-13 20:39
professionalWayne Gaylard18-Nov-13 20:39 
GeneralRe: how to write MAX query Pin
spanner2118-Nov-13 21:11
spanner2118-Nov-13 21:11 
GeneralRe: how to write MAX query Pin
Wayne Gaylard18-Nov-13 21:17
professionalWayne Gaylard18-Nov-13 21:17 
AnswerRe: how to write MAX query Pin
Mycroft Holmes18-Nov-13 21:11
professionalMycroft Holmes18-Nov-13 21:11 
AnswerRe: how to write MAX query Pin
Peter Leow18-Nov-13 23:39
professionalPeter Leow18-Nov-13 23:39 
Questionhow can optimize a query in sql server Pin
mhd.sbt17-Nov-13 4:15
mhd.sbt17-Nov-13 4:15 
AnswerRe: how can optimize a query in sql server Pin
Maciej Los17-Nov-13 5:44
mveMaciej Los17-Nov-13 5:44 
GeneralRe: how can optimize a query in sql server Pin
PIEBALDconsult18-Nov-13 15:42
mvePIEBALDconsult18-Nov-13 15:42 
AnswerRe: how can optimize a query in sql server Pin
Jörgen Andersson18-Nov-13 3:00
professionalJörgen Andersson18-Nov-13 3:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.