python中sql语句多个 查询条件的怎么写

2025-02-25 00:29:59
推荐回答(1个)
回答1:

python中有很多字符串连接方式,今天在写代码,顺便总结一下:

  1.   最原始的字符串连接方式:str1 + str2

  2.   python 新字符串连接语法:str1, str2

  3.   奇怪的字符串方式:str1 str2

  4.   % 连接字符串:‘name:%s; sex: ’ % ('tom', 'male')

  5.   字符串列表连接:str.join(some_list)

第四种功能比较强大,借鉴了C语言中 printf 函数的功能,如果你有C语言基础,看下文档就知道了。这种方式用符号“%”连接一个字符串和一组变量,字符串中的特殊标记会被自动用右边变量组中的变量替换。


试试这个

results = self.db.query(
    'SELECT  LP.Id LineProductId,LP.SupplierLineTitle,LP.MainTitle,LP.SubTitle,LP.ShowTitle ,LPC.CityId DestinationCityId,\
     LPC.CityName DestinationCityName,LP.Days,LP.DataFlag,LP.IfDel,LP.RecomImage_Ids AS LineProductRecomImage\
     FROM [TCZiZhuYou].dbo.[ZZY_LineProduct] LP WITH(NOLOCK)\
     INNER JOIN [TCZiZhuYou].dbo.[ZZY_LineProductCity] LPC WITH(NOLOCK) ON LPC.LineProduct_Id=LP.Id AND LPC.DataFlag=1 AND LPC.IsDestination=1 \
     WHERE LP.Id=%d  AND LP.LineProductType=%d '  %( line_id, line_type) )[0]