mysql 选择同一行中的数据

bfnvny8b  于 2023-04-05  发布在  Mysql
关注(0)|答案(1)|浏览(110)

my tabel
我需要知道如何编写这样的代码:
如果account_id 2的quiz_num_1数据不是quiz_null,则进行打印,如果account_id 2的quiz_num_1数据是quiz_null,则进行不同的打印,account_id可由变量名控制:user_account_id = 1或2
有人能帮我吗?
我试着这么做,但没有成功

mycursor.execute(f"SELECT account_id FROM quizzes_lib WHERE account_id = '{user_account_id}'AND SELECT quiz_num_1 FROM quizzes_lib WHERE quiz_num_1 = 'quiz_null'")
 #mycursor.execute("SELECT quiz_num_1 FROM quizzes_lib Where quiz_num_1 = 'quiz_null'")
 if mycursor.fetchall():
   print("there is no quizzes in your library")
 else:
   print("there is __ in your library")
vlju58qv

vlju58qv1#

mycursor.execute(f"SELECT account_id, quiz_num_1 FROM quizzes_lib WHERE account_id = '{ user_account_id }' AND quiz_num_1 != 'quiz_null'")
if mycursor.fetchall():
  print("there is quizzes in your library")
else:
  print("no quizzes")

相关问题