[Show all top banners]

phone
Replies to this thread:

More by phone
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 Please help on Sql query
[VIEWED 6151 TIMES]
SAVE! for ease of future access.
Posted on 07-03-19 5:11 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

​Hello , I have a table called Student consisting of Columns Name, and DateOfBirth. I would like to create a query Which Selects all Name whose DateOfBirth is on the same day. The DateOfBirth Column datatype is in DateTime format. I want the result in the Date format. In my table below I want row 1,2, and 7 for day 1 and 3,4 for day 2 as a result of the query.


 
Posted on 07-03-19 6:36 PM     [Snapshot: 49]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Use "GROUP BY" on DOB and get list of names in one column by using STRING AGG functions.
 
Posted on 07-03-19 6:38 PM     [Snapshot: 52]     Reply [Subscribe]
Login in to Rate this Post:     1       ?     Liked by
 

select DATE_OF_BIRTH, LISTAGG(NAME, ',') WITHIN GROUP (ORDER BY NAME) AS NAME
from TABLE
GROUP BY DATE_OF_BIRTH;

Good Luck !!!
 
Posted on 07-04-19 10:17 AM     [Snapshot: 162]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hello basnyatt,

When I run the query it throws the error saying:
"The function 'ListAgg' may not have a WITHIN GROUP clause."
 
Posted on 07-05-19 10:21 AM     [Snapshot: 259]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

what RDBMS are you using
 
Posted on 07-05-19 12:18 PM     [Snapshot: 312]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

select x.*, rownum as day_num from (
select to_date((to_char(dateOfBirth, 'YYYY-MM-DD')),'YYYY-MM-DD') date_of_Birth, listagg(Name, ',') within group(order by Name) Name_of_students
from student
group by to_date((to_char(dateOfBirth, 'YYYY-MM-DD')),'YYYY-MM-DD')
) x;


this works for Oracle. If you are using mysql try using string_agg instead of listagg.
 
Posted on 07-06-19 1:21 PM     [Snapshot: 410]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hello basnyatt,

I am using Microsoft SQL Server 2012.
 
Posted on 07-07-19 11:37 AM     [Snapshot: 489]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hello raajkm,

I need the skript for Microsoft SQL Server. Please help me.


Last edited: 08-Jul-19 08:07 AM

 
Posted on 07-08-19 12:14 PM     [Snapshot: 642]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

WELL i do not use sql server 2012 but you might use the query as;

select to_date((to_char(S1.dateOfBirth, 'YYYY-MM-DD')),'YYYY-MM-DD') date_of_Birth,
stuff ((select distinct ','+ Name from student s2 where s2.name=s1.name FOR XML PATH(' ')),1,1,' ') as name_of_students

from student s1 group by to_date((to_char(S1.dateOfBirth, 'YYYY-MM-DD')),'YYYY-MM-DD')
Last edited: 08-Jul-19 12:16 PM
Last edited: 08-Jul-19 12:17 PM

 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 30 days
Recommended Popular Threads Controvertial Threads
What are your first memories of when Nepal Television Began?
nrn citizenship
Send Parcels from USA to Nepal & Worldwide.
Why is every youths leaving Nepal? Why are not youths entering politics and serving the country, starting business etc?
TPS Work Permit/How long your took?
महँगो अण्डाको पिकल्प : कुखुरा र खोर भाडामा लिने
Travelling on TPS advance travel document to different country...
Informatica consultancy share
काेराेना सङ्क्रमणबाट बच्न Immunity बढाउन के के खाने ?How to increase immunity against COVID - 19?
TPS Renewal Reregistration
Nepali doctors future black or white usa ?
हेर अमेरिकामा नेपालीहरुको बेज्जत
Thank you for the sajha policy
मन भित्र को पत्रै पत्र!
Travelling to Nepal - TPS AP- PASSPORT
Are you ready to know the truth?
चितवनको होस्टलमा १३ वर्षीया शालिन पोखरेल झुण्डिएको अवस्था - बलात्कार पछि हत्याको शंका - होस्टेलहरु असुरक्षित
Another Song Playing In My Mind
Does the 180 day auto extension apply for TPS?
WHAT DO YOU GUYS THINK ABOUT THIS?
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters