« first day (2414 days earlier)      last day (1904 days later) » 

11:02
christmas
yes im awake @AndyK ;P
good morning
afternoon*
@Tomm hey bud
happy christmas
merry christmas :)
@Tomm cheers
 
1 hour later…
12:35
Is there a way to get the count where of the columns that are LIKE a column? The CLIENT_ID has a varchar, and any children have the same CLIENT_ID but with a letter at the end (4567 is a parent, 4567A is the first child, 4567B is the second, etc). I am trying to get the count of children for each parent.
I've tried this: SELECT CLIENT_ID, COUNT(*) AS CHILDREN FROM CLIENT GROUP BY CLIENT_ID HAVING CLIENT_ID LIKE CONCAT(CLIENT_ID, '%')
I only get a count of 1 for everyone
12:49
There is no direct approach i know of to give it a concat of id and childname. you could do that in a 2 queries joined together
You can use the OVER()
OVER(Partition by Id Order by Id) and then i would join that with a description of what 1,2,3,4 = a,b,c,d etc and then use concat
@Hpjchobbes
13:43
or you can remove last char of a child and group by that
that wouldnt necessarily be a valid pairing
only in case when parent has more then 26 children
id, name, parent
1, 'a', null
2, 'b', null
3, 'c', 2
i doubt his table looks like that
then his query would work as he would grp by parent
and if his ID is 4567, then grouping on those 10 wouldnt mean they were all meant to be in the same group... they could be, but we can't know for sure :)
without any actual data we can only guess :)
13:48
(4567 is a parent, 4567A is the first child, 4567B is the second, etc).
maybe i read it wrong... i read it as if first node has ID 4567 and the child has any id, first child would be called 4567A, second child 4567B
you are correct
then i would group removing last char like you suggested
guess my brain is still on xmas holiday
The CLIENT_ID column is always unique and will have either a number, like 4567, or if the record is for a child it will always have a letter following the parent number
sql server? oracle?
SQL Server
I do have a column that tells me if this record is a potential parent. That will be 1 if it MIGHT have children or 0 for any child record
I just wish whoever designed this table would have just added a column to reference the parent record...
with cte as (
select '456A' as Child
union
select '456R' as Child
union
select '456F' as Child
union
select '457B' as Child
union
select '457C' as Child
)
select LEFT(Child, LEN(Child) - 1) as Parent, count(*) ChildCount from cte
group by LEFT(Child, LEN(Child) - 1)
they did referenced it within ChildId ... you can always join by that
but yes, it would be better if they split it in 2 columns ParentId 457, ChildId A

« first day (2414 days earlier)      last day (1904 days later) »