gpt4 book ai didi

django - 在原始查询 Django 中将文字百分号 (%) 添加到我的计算中

转载 作者:行者123 更新时间:2023-11-29 13:10:27 34 4
gpt4 key购买 nike

在查询中添加百分比符号时出现错误:

Exception Type:IndexError
Exception Value:tuple index out of range.

views.py

class groupdatagercekzamanliveriListView(ListAPIView):
query2 = gercekzamanlıveri.objects.raw("""SELECT 1 as id,
CONCAT(ROUND((SUM(net_uretim_miktari)/SUM(teorik_uretim_miktari)::float*100)),'%') as tee, FROM tee_gercekzamanlıveri
INNER JOIN tee_isyerleri ON tee_gercekzamanlıveri.isyeri_id= tee_isyerleri.id
INNER JOIN tee_malzemeler ON tee_gercekzamanlıveri.malzeme_id= tee_malzemeler.id
INNER JOIN tee_isyerimalzemebilgileri ON tee_isyerimalzemebilgileri.isyeri_id= tee_gercekzamanlıveri.isyeri_id
AND tee_isyerimalzemebilgileri .malzeme_id = tee_gercekzamanlıveri.malzeme_id) as a GROUP BY isyeri_id""")

queryset = query2
serializer_class = groupdatagercekzamanlıveriserializer

序列化器.py

class groupdatagercekzamanlıveriserializer(serializers.Serializer):

id = serializers.IntegerField()
tee = serializers.CharField()

当我使用 "a" 作为 "%" 的字符串时没问题:

CONCAT(ROUND((SUM(net_uretim_miktari)/SUM(teorik_uretim_miktari)::float*100)),'a') as tee

结果: “tee”:80a

最佳答案

根据documentation (GIYF 首次命中 django sql "%" - 至少对我而言)你必须将它加倍才能将字符识别为文字,例如:

--
CONCAT(
ROUND(
(SUM(net_uretim_miktari) / SUM(teorik_uretim_miktari)::float * 100)
),
'%%'
) as tee, FROM tee_gercekzamanlıveri
--

关于django - 在原始查询 Django 中将文字百分号 (%) 添加到我的计算中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55489045/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com