How to write Sql server script

Hi yosaisz

Chex mix
Chips
Same day

Only

Meena
Nuts

how do you know that? the person has not specified a clear requirement. highlighting in yellow is not a requirement so it is open to anyone's interpretation :wink:

create table snacks(snackid int not null identity(1,1), 
snackname nvarchar(100))
create table students(studentid int not null identity(1,1), 
firstname nvarchar(50), lastname nvarchar(50))
create table eats(studentid int not null, 
snackid int not null, dateofsnack datetime)

insert into snacks
select  'Chex Mix' union
select  'Chips'   

insert into students(firstname, lastname)
select  'Saru','Khan' union
select  'Amithabh','Bachchan' union
select 'Nima', 'Rai'

insert into eats(studentid, snackid,dateofsnack)
select  1,1,'2019-04-03 06:00:00.000' union
select  1,2,'2019-04-03 09:04:00.000' union
select  3,1, '2019-04-03 09:04:00.000' union
select  3,2, '2019-04-02 09:04:00.000' 

select * 
From students s
join (select studentid, 
            cast(dateofsnack as date) _dateofsnack 
	   from eats 
	  group by studentid, cast(dateofsnack as date) 
	 having count(1) > 1 
	   ) e on s.studentid = e.studentid
join eats e2 on e2.studentid = s.studentid
join snacks k on k.snackid = e2.snackid

drop table snacks
drop table students
drop table eats

image

Hi yosaisz

How are you?

Long time no see

:+1::+1::slightly_smiling_face::slightly_smiling_face:

Hi yosaisz

Because

I have been following this post
From the very beginning

Where I was trying to understand
And came up with a solution

However
Jay
Wanted a different solution

hello Harishgg1. so again highlighting in yellow a picture of data is not a good requirement. He needs to state in plain English what he wants.

His reply was meant for me

As I had asked him