2020-08-06

mysql
1、求出连续三天有销售记录的店铺

select a.shopid
from sales_record a
left join sales_record b
on a.shopid = b.shopid and
datediff(str_to_date(b.dt, '%Y-%m-%d'),str_to_date(a.dt, '%Y-%m-%d')) = 1
left join sales_record c
on b.shopid = c.shopid and
datediff(str_to_date(c.dt, '%Y-%m-%d'),str_to_date(b.dt, '%Y-%m-%d')) = 1
where a.sale > 0 and b.sale > 0 and c.sale > 0
group by shopid;


python
1、下面这段代码的输出结果是什么?请解释

def extendlist(val,list[]):
  list.append(val)
  return list
list1 = extendlist(10)
list2 = extendlist(123,[])
list3 = extendlist('a')

print('list1 = %s' %list1)
print('list1 = %s' %list2)
print('list1 = %s' %list3)

输出结果:



2、下面这段代码的输出结果是什么?请解释

num =9
def f1()
  num = 20
def f2()
  print(num)
f2()
f1()
f2()

输出结果:


num不是个全局变量,所以每个函数都得到了自己的num拷贝,如果你想修改num,则必须用global关键字声明

num =9
def f1():
  global = num
  num = 20
def f2():
  print(num)
f2()
f1()
f2()

3、下面这段代码的输出结果是什么?请解释

#第一段
l = []
for i in range(10):
    l.append({'num': i})
print(l)

#第二段
l = []
a = {'num':0}
for i in range(10):
    a['num'] = i
    l.append(a)
print(l)

第一段,{'num':i}的循环里面,每一次循环都产生一个新的字典类型
4、从两个列表取出相同和不同的元素
list1 = [1,2,3,4,5]
list2 = [2,3,5,7,8,9]

#取出相同的元素
a = []
for i in list1:
    for j in list2:
        if i == j:
            a.append(i)
print(a)

#取出不同的元素
b = []
for i in (list1 + list2):
    if i not in a:
        b.append(i)
print(b)

你可能感兴趣的:(2020-08-06)