Jump to content

Need help in SQL Query


Recommended Posts

Posted

 

SQL Gurus, 

 

In the following link I have posted the input and expected output: 

https://image.ibb.co/kfkOeU/Request.png

The requirement is I want to do groupby of  Children id, Pranetid and snack id

but if the snack id changes in between and shifts to the previous one, then I want SQL to consider it as new group...   Is there any way we can achieve this? Request.png

 

https://ibb.co/c4VZm9

 

Thanks in advance..

Posted
1 hour ago, ImBack said:

 

SQL Gurus, 

 

In the following link I have posted the input and expected output: 

https://image.ibb.co/kfkOeU/Request.png

The requirement is I want to do groupby of  Children id, Pranetid and snack id

but if the snack id changes in between and shifts to the previous one, then I want SQL to consider it as new group...   Is there any way we can achieve this? Request.png

 

https://ibb.co/c4VZm9

 

Thanks in advance..

Bookmark for morning.

Posted

 

Select ChildrenId, Parentid, snackid, count(*) from table

group by childrenid,  Parentid, snackid 

If you want to group by output field add output field and use rowid or partition.

 

Posted
2 minutes ago, SeenuDumalaHalwa said:

 

Select ChildrenId, Parentid, snackid, count(*) from table

group by childrenid,  Parentid, snackid 

If you want to group by output field add output field and use rowid or partition.

 

When using rowid or partition it is not recognizing the changes that happened in between..

Posted

CREATE TABLE TEST123( cid VARCHAR(5),
    pid VARCHAR(5),
    sid VARCHAR(5));
    
INSERT INTO TEST123  VALUES ('1','1','a');
INSERT INTO TEST123 VALUES ('1','1','a');
INSERT INTO TEST123 VALUES ('1','1','b');
INSERT INTO TEST123 VALUES ('1','1','b');
INSERT INTO TEST123 VALUES ('1','1','a');
INSERT INTO TEST123 VALUES ('1','1','a');
 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...