复杂的查询

ZJadjacent.objects.annotate(t_pci=F('cellto__pci'))
<QuerySet [<ZJadjacent: 358036728805064833>, <ZJadjacent: 358036733100032129>, <ZJadjacent: 358046645884551297>, <ZJadjacent: 358181868634898561>, <ZJadjacent: 358184067658154113>, <ZJadjacent: 359393530448707713>, <ZJadjacent: 359545263053340801>, <ZJadjacent: 359545280233209985>, <ZJadjacent: 360069721509855361>, <ZJadjacent: 360156587223416961>, <ZJadjacent: 454197262696317057>, <ZJadjacent: 454197271286251649>, <ZJadjacent: 454200565526167681>, <ZJadjacent: 454200569821134977>, <ZJadjacent: 454202760254455937>, <ZJadjacent: 454202768844390529>, <ZJadjacent: 454204959277711489>, <ZJadjacent: 454204963572678785>, <ZJadjacent: 454204967867646081>, <ZJadjacent: 454208257812594817>, '...(remaining elements truncated)...']>
ZJadjacent.objects.annotate(t_pci=F('cellto__pci')).values('t_pci','cellfrom')
<QuerySet [{'cellfrom': 83361922, 't_pci': 331}, {'cellfrom': 83361923, 't_pci': 331}, {'cellfrom': 83364231, 't_pci': 331}, {'cellfrom': 83395715, 't_pci': 331}, {'cellfrom': 83396227, 't_pci': 331}, {'cellfrom': 83677827, 't_pci': 331}, {'cellfrom': 83713155, 't_pci': 331}, {'cellfrom': 83713159, 't_pci': 331}, {'cellfrom': 83835265, 't_pci': 331}, {'cellfrom': 83855490, 't_pci': 331}, {'cellfrom': 105751041, 't_pci': 331}, {'cellfrom': 105751043, 't_pci': 331}, {'cellfrom': 105751810, 't_pci': 331}, {'cellfrom': 105751811, 't_pci': 331}, {'cellfrom': 105752321, 't_pci': 331}, {'cellfrom': 105752323, 't_pci': 331}, {'cellfrom': 105752833, 't_pci': 331}, {'cellfrom': 105752834, 't_pci': 331}, {'cellfrom': 105752835, 't_pci': 331}, {'cellfrom': 105753601, 't_pci': 331}, '...(remaining elements truncated)...']>
ZJadjacent.objects.annotate(t_pci='cellto__pci').values('t_pci','cellfrom')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\Administrator\PycharmProjects\cellsmap\venv\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\Users\Administrator\PycharmProjects\cellsmap\venv\lib\site-packages\django\db\models\query.py", line 971, in annotate
    self._validate_values_are_expressions(args + tuple(kwargs.values()), method_name='annotate')
  File "C:\Users\Administrator\PycharmProjects\cellsmap\venv\lib\site-packages\django\db\models\query.py", line 1247, in _validate_values_are_expressions
    ', '.join(invalid_args),
TypeError: QuerySet.annotate() received non-expression(s): cellto__pci.
ZJadjacent.objects.annotate(t_pci=F('cellto__pci'), t_freq=F('cellto__freq')).values('t_pci','cellfrom','t_freq')
<QuerySet [{'cellfrom': 83361922, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 83361923, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 83364231, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 83395715, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 83396227, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 83677827, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 83713155, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 83713159, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 83835265, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 83855490, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 105751041, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 105751043, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 105751810, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 105751811, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 105752321, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 105752323, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 105752833, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 105752834, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 105752835, 't_pci': 331, 't_freq': 'D1'}, {'cellfrom': 105753601, 't_pci': 331, 't_freq': 'D1'}, '...(remaining elements truncated)...']>
ZJadjacent.objects.annotate(t_pci=F('cellto__pci'), t_freq=F('cellto__freq')).values('t_pci','cellfrom','t_freq').count()
838118
ZJadjacent.objects.annotate(t_pci=F('cellto__pci'), t_freq=F('cellto__freq')).values('t_pci','cellfrom','t_freq').distinct().annotate(num=Count('cellfrom'))
<QuerySet [{'cellfrom': 83361921, 't_pci': 15, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 17, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 27, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 29, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 83, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 86, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 90, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 91, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 92, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 100, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 101, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 115, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 132, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 133, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 134, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 181, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 229, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 253, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 254, 't_freq': 'D1', 'num': 1}, {'cellfrom': 83361921, 't_pci': 273, 't_freq': 'D1', 'num': 1}, '...(remaining elements truncated)...']>
ZJadjacent.objects.annotate(t_pci=F('cellto__pci'), t_freq=F('cellto__freq')).values('t_pci','cellfrom','t_freq').distinct().annotate(num=Count('cellfrom')).filter(num__exact=2)
<QuerySet [{'cellfrom': 83377290, 't_pci': 433, 't_freq': 'D2', 'num': 2}, {'cellfrom': 83377291, 't_pci': 433, 't_freq': 'D2', 'num': 2}, {'cellfrom': 83377292, 't_pci': 433, 't_freq': 'D2', 'num': 2}, {'cellfrom': 83377294, 't_pci': 433, 't_freq': 'D2', 'num': 2}, {'cellfrom': 83379331, 't_pci': 393, 't_freq': 'D1', 'num': 2}, {'cellfrom': 83379334, 't_pci': 394, 't_freq': 'D2', 'num': 2}, {'cellfrom': 83379841, 't_pci': 393, 't_freq': 'D1', 'num': 2}, {'cellfrom': 83379842, 't_pci': 393, 't_freq': 'D1', 'num': 2}, {'cellfrom': 83379843, 't_pci': 394, 't_freq': 'D2', 'num': 2}, {'cellfrom': 83385222, 't_pci': 393, 't_freq': 'D1', 'num': 2}, {'cellfrom': 83388289, 't_pci': 433, 't_freq': 'D2', 'num': 2}, {'cellfrom': 83388291, 't_pci': 430, 't_freq': 'D1', 'num': 2}, {'cellfrom': 83391361, 't_pci': 86, 't_freq': 'D1', 'num': 2}, {'cellfrom': 83391876, 't_pci': 393, 't_freq': 'D1', 'num': 2}, {'cellfrom': 83392899, 't_pci': 393, 't_freq': 'D1', 'num': 2}, {'cellfrom': 83392905, 't_pci': 394, 't_freq': 'D2', 'num': 2}, {'cellfrom': 83399043, 't_pci': 1, 't_freq': 'D3', 'num': 2}, {'cellfrom': 83400067, 't_pci': 1, 't_freq': 'D1', 'num': 2}, {'cellfrom': 83401094, 't_pci': 100, 't_freq': 'D2', 'num': 2}, {'cellfrom': 83404417, 't_pci': 30, 't_freq': 'D1', 'num': 2}, '...(remaining elements truncated)...']>
ZJadjacent.objects.annotate(t_pci=F('cellto__pci'), t_freq=F('cellto__freq')).values('t_pci','cellfrom','t_freq').distinct().annotate(num=Count('cellfrom')).filter(num__exact=2).count()
371

猜你喜欢

转载自blog.csdn.net/qq_27361945/article/details/83478088