1、mysql数据库复合索引是(a,b,c),按照abc顺序建立复合索引idx_a_b_c,以下查询语句中使用到索引idx_a_b_c的有哪些?
A、(a) B、(b) C、(b,c) D、(a,b) E、(a,b,c)
解答:B、C
复合索引:Mysql从左到右的使用索引中的字段,一个查询可以只使用索引中的一部份,但只能是最左侧部分。例如索引是key index (a,b,c). 可以支持a | a,b| a,b,c 3种组合进行查找,但不支持 b,c进行查找 .当最左侧字段是常量引用时,索引就十分有效。
2、crontab定时任务:每周1到周5,下午1点和8点定时执行,怎么写?
解答:0 13,20 * * 1,2,3,4,5
3、下面C语言程序的打印结果是啥?
备注:涉及指针的一段c语言代码——–记不清了!
4、java代码片段,打印结果是啥?
for(i < a(); i < b(); i++){
print("z");
}
public int a():
print("x");
return 0;
public int b():
print("y");
return 5;
解答:xyzyzyzyzyz
执行顺序是,先执行第一个表达式i < a();(这个只有在第一次循环的时候用到,后面的循环就不用了)。
接着判断第二个表达式i < b();,非零就执行循环体,零就退出,
接着运行循环体print("z");
最后运行第三个表达式i++(改变循环条件)
5、mysql的题目-查询表中所有工资大于本部门平均工资得员工的数量和部门名——-具体的表啥的记不清了
参考这里-几乎一样的题目。
【待解决】6、开发一个小程序,起3个线程,线程id分别为:A、B、C,每个线程打印10便自己的线程ID
小程序打印的最终结果是ABCABC……以此类推!
解答:请用python实现
7、读取文件f.txt,把重复的名字和重复数量,打印出来。
1,asdasd,39
2,asdasd1,39
3,asdasd,39
4,asdasd2,39
5,asdasd,39
6,asdasd3,39
7,asdasd2,39
8,asdasd1,39
解答:
#coding=utf-8
f = open("f.txt")
count_dict = {}
for line in f.readlines():
name = line.strip().split(",")[1]
if name in count_dict:
count_dict[name] += 1
else:
count_dict.setdefault(name, 1)
for key,value in count_dict.items():
print("%s:%d" % (key, value))
8、计算两个日期之间有多少天?
解答:此题不简单!注意考虑清楚再答题!
可以参考本人的github-这里
# By Websten from forums
#
# Given your birthday and the current date, calculate your age in days.
# Account for leap days.
#
# Assume that the birthday and current date are correct dates (and no
# time travel).
#
def judge_year(year):
sumDaysYears = 365
feb = 28
if ((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0) :
sumDaysYears = 366
feb = 29
daysOfMonths = [ 31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
return sumDaysYears, daysOfMonths
def sumDays(year, month, day):
sumDaysYears, daysOfMonths = judge_year(year)
if month >= 2:
i = 0
sum1 = 0
while i < month-1 :
#print i
sum1 = sum1 + daysOfMonths[i]
i += 1
sumDaysFromOnetoMonthDay = sum1 + day - 1
else :
sumDaysFromOnetoMonthDay = day - 1
print sumDaysFromOnetoMonthDay, sumDaysYears - sumDaysFromOnetoMonthDay
return sumDaysFromOnetoMonthDay, sumDaysYears - sumDaysFromOnetoMonthDay
def daysBetweenDates(year1, month1, day1, year2, month2, day2):
##
# Your code here.
##
sum1Year1, sum2Year1 = sumDays(year1, month1, day1)
sum1Year2, sum2Year2 = sumDays(year2, month2, day2)
bwteenYears = year2 - year1
if bwteenYears < 0 :
print "year2 must > year1"
elif bwteenYears == 0 :
return sum1Year2
else :
if bwteenYears >= 2 :
i = 0
sumTmp = 0
while i < bwteenYears-1 :
sumDaysWholeYear, daysOfMonths = judge_year(year1 + i + 1)
sumTmp = sumTmp + sumDaysWholeYear
i += 1
return sum2Year1 + sum1Year2 + sumTmp
return sum2Year1 + sum1Year2
# Test routine
def test():
test_cases = [((2012,1,1,2012,2,28), 58),
((2012,1,1,2012,3,1), 60),
((2011,6,30,2012,6,30), 366),
((2011,1,1,2012,8,8), 585 ),
((1900,1,1,1999,12,31), 36523)]
for (args, answer) in test_cases:
result = daysBetweenDates(*args)
print result
if result != answer:
print "Test with data:", args, "failed"
else:
print "Test case passed!"
test()