ImBack Posted October 7, 2018 Report Posted October 7, 2018 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? https://ibb.co/c4VZm9 Thanks in advance.. Quote
Mitron Posted October 7, 2018 Report Posted October 7, 2018 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? https://ibb.co/c4VZm9 Thanks in advance.. Bookmark for morning. Quote
SeenuDumalaHalwa Posted October 7, 2018 Report Posted October 7, 2018 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. Quote
ImBack Posted October 7, 2018 Author Report Posted October 7, 2018 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.. Quote
ImBack Posted October 7, 2018 Author Report Posted October 7, 2018 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'); Quote
minimalist Posted October 7, 2018 Report Posted October 7, 2018 A bit lazy to explain right now, but try using #views if it rings a bell! Quote
Allarinaresh10 Posted October 8, 2018 Report Posted October 8, 2018 41 minutes ago, ImBack said: Lift Quote
argadorn Posted October 8, 2018 Report Posted October 8, 2018 partition like row preceding by lo cheyachu anukunta ... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.