mysql
1、求出連續(xù)三天有銷售記錄的店鋪
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峡蟋、下面這段代碼的輸出結(jié)果是什么坟桅?請解釋
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)
輸出結(jié)果:
2、下面這段代碼的輸出結(jié)果是什么蕊蝗?請解釋
num =9
def f1()
num = 20
def f2()
print(num)
f2()
f1()
f2()
輸出結(jié)果:
num不是個全局變量仅乓,所以每個函數(shù)都得到了自己的num拷貝,如果你想修改num蓬戚,則必須用global關(guān)鍵字聲明
num =9
def f1():
global = num
num = 20
def f2():
print(num)
f2()
f1()
f2()
3方灾、下面這段代碼的輸出結(jié)果是什么?請解釋
#第一段
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}的循環(huán)里面碌更,每一次循環(huán)都產(chǎn)生一個新的字典類型
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)