Re: Recreating SQL query in ORM

2019-08-01 Thread Jonathan Spicer
Thanks Simon, that's a great help. On Wednesday, 31 July 2019 15:03:55 UTC+1, Simon Charette wrote: > > Hello, > > assuming you have a FullMatch model mapped to your FullMatches table > the following should do. > > FullMatch.objects.filter( > job_id=job_id, > ).values( > seq=Concat('loadin

Re: Recreating SQL query in ORM

2019-07-31 Thread Simon Charette
Hello, assuming you have a FullMatch model mapped to your FullMatches table the following should do. FullMatch.objects.filter( job_id=job_id, ).values( seq=Concat('loading_code', ...), ids=Concat('loading_id', ), ).annotate( total=Count('*'), ).order_by('-total') Using .value

Re: Recreating SQL query in ORM

2019-07-30 Thread Yogesh K SonI
yes On Tuesday, July 30, 2019 at 10:26:56 PM UTC+5:30, Jonathan Spicer wrote: > > Hello, > > I have an sql query that I would like to recreate using the ORM. Would it > be possible for someone to give me some pointers. > > select count(*) as total, > > concat(loading_code,code1_c

Re: Recreating SQL query in ORM

2019-07-30 Thread Jonathan Spicer
Hello John, I did try that but it complained about the query not containing the primary key. I did wonder if there are methods within the ORM that can replicate it, the tricky part being creating a value to group by from concatenated rows. On Tuesday, 30 July 2019 19:14:32 UTC+1, John Bagiliko

Re: Recreating SQL query in ORM

2019-07-30 Thread John Bagiliko
Do you want to make this exact query in Django? Then use Your_model.objects.raw("the query here except the last semi colon") On Tue, Jul 30, 2019, 4:56 PM Jonathan Spicer wrote: > Hello, > > I have an sql query that I would like to recreate using the ORM. Would it > be possible for someone to gi

Recreating SQL query in ORM

2019-07-30 Thread Jonathan Spicer
Hello, I have an sql query that I would like to recreate using the ORM. Would it be possible for someone to give me some pointers. select count(*) as total, concat(loading_code,code1_code,code2_code,code3_code,code4_code) as seq, concat(loading_id,',',code1_id,'