sql

Download sql

If you can't read please download the document

Upload: bangarraju

Post on 09-Dec-2015

218 views

Category:

Documents


2 download

DESCRIPTION

sql questions

TRANSCRIPT

CREATE TABLE Employee(`id` int, `name` varchar(15), `sal` int, `did` int);INSERT INTO Employee(`id`, `name`, `sal`, `did`)VALUES(1, 'A', 1000, 1), (2, 'B', 2000, 1), (3, 'C', 3000, 2), (4, 'D', 4000, 2), (5, 'E', 5000, 4); CREATE TABLE Department(`did` int, `dname` varchar(15)); INSERT INTO Department(`did`, `dname`)VALUES(1, 'Math'), (2, 'Phy'), (3, 'Che'); -> select name,sal from Employee;-> select Department.dname, Employee.sal from Employee INNER JOIN Department ON Employee.did=Department.did;-> select Dpartment.dept_name, -> SELECT sal FROM Employee where sal=(select max(sal) from Employee where sal < (select max(sal) from Employee));or select max(sal) from Employee where sal < (select max(sal) from Employee);-> select Department.dname, sum(Employee.sal) as total From Employee INNER JOIN Department where Department.did=Employee.did Group By Department.dname;-> select Employee.name,Department.dname From Employee INNER JOIN Department where Employee.did=Department.did;select Department.dname, Employee.sal From Employee INNER JOIN Department where Employee.did=Department.did Order by Employee.sal DESC;select Department.dname, Employee.sal From Employee INNER JOIN Department where Employee.sal >= 5000 and Employee.did=Department.did;select distinct Department.dname From Employee INNER JOIN Department where (Department.dname like '%M%' or Department.dname like '%h%');CREATE TABLE runners(`id` int, `name` varchar(15));INSERT INTO runners(`id`, `name`)VALUES(1, 'John Deo'), (2, 'Jane Deo'), (3, 'Alice Jones'), (4, 'Bobby'), (5, 'Lisa');CREATE TABLE races(`id` int, `event` varchar(15), `w_id` int);INSERT INTO races(`id`, `event`, `w_id`)VALUES(1, '100m',2), (2, '500m',3), (3, 'cross', 2), (4, 'trin',NULL);http://www.plus2net.com/sql_tutorial/sql_sum.phphttp://stackoverflow.com/questions/19851343/mysql-select-column-names-containing-a-stringclass Solution: # @param root, a tree node # @return a list of lists of integers def levelOrder(self, root): solution=[] if root == None: return solution levelToProcess =[root] while len(levelToProcess)>0: numbersLevel =[] nextLevel = [] for temp in levelToProcess: numbersLevel.append(temp.val) if temp.left != None: nextLevel.append(temp.left) if temp.right != None: nextLevel.append(temp.right) solution.append(numbersLevel) levelToProcess = nextLevel return solution class Solution: # @param root, a tree node # @return a list of integers def inorderTraversal(self, root): stack = [] node = root solution = [] while node!= None or len(stack)>0: if node != None: stack.append(node) node = node.left else: node = stack.pop() solution.append(node.val) node = node.right return solution #Python program that finds most frequent word in a .txt file,import refrom collections import Counterwith open('your_file.txt') as f: passage = f.read()words = re.findall(r'\w+', passage)cap_words = [word.upper() for word in words]word_counts = Counter(cap_words)#!/usr/bin/env pythondef word_occurrence(file, count): word_with_count = {} with open(file) as f: for line in f.readlines(): for word in line.split(): if word in word_with_count: word_with_count[word] += 1 else: word_with_count[word] = 1 words = [] x = max(word_with_count.values()) for key, value in word_with_count.iteritems(): if value == x: print "word is ", key if value == count: words.append(key) return wordsabc = word_occurrence("/home/xbandiv/abc.txt",3)print abcfrom itertools import combinations#from itertools import izipl = [1,2,3,4,5,6]lt = []for i,j in combinations(l,2): if i+j==7: lt.append([i,j]) print i,j print ltlista = [1, 2, 3, None, None, None]listb = [4, 5, 3]listc = []for i , j in zip(lista[0:(len((lista))/2)], listb): listc.append(i) listc.append(j)print listc