sankar
sankar

Reputation: 357

Django mysql query

I am new to django and I have difficulty in constructing django query. Can anyone please help me to construct this query into django query?

SELECT DISTINCT mt.ID_Number 
FROM measurement_test mt 
WHERE mt.Start_Date IN('2012-02-15','2012-06-14') 
AND mt.ID_Number != ''

Upvotes: 1

Views: 455

Answers (2)

Vivek S
Vivek S

Reputation: 5550

You can use the following,

measurement_test.objects.filter(~Q(ID_Number=''), Start_Date__in=['2012-02-15','2012-06-14']).values('ID_Number').distinct()

Upvotes: 1

Reinbach
Reinbach

Reputation: 771

Assuming "measurement_test" is the object the models the relevant table.

measurement_test.objects.values_list(ID_Number).filter(Start_Date__in=('2012-02-15','2012-06-14')).exclude(ID_Number='').distinct()

Upvotes: 3

Related Questions