Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select max(abs(mycol)) from mytbl
- select max(abs(mycol)) from mytbl
- select n+abs(mycol)
- from zzz
- where abs(mycol)=(select max(abs(mycol)) from mytbl);
- select word, big from myTable order by abs(big)
- select sum(abs(big)) as sumbig,
- sum(abs(expensive)) as sumexpensive,
- sum(abs(smart)) as sumsmart,
- sum(abs(fast)) as sumfast
- from MyTable;
- word property value
- select word, 'big' as property, big as value from soquestion
- UNION ALLL
- select word, 'expensive', expensive from soquestion
- UNION ALL
- ...
- select word, max(value),
- (select property from soquestion t2
- where t1.word = t2.word and t2.value = max(t1.value))
- from soquestion t1
- group by word
- #!/usr/bin/env python
- import sqlite3
- conn = sqlite3.connect('so_question.sqlite')
- cur = conn.cursor()
- cur.execute('create table soquestion (word, big, expensive, smart, fast)')
- cur.execute("insert into soquestion values ('dog', 9, -10, -20, 4)")
- cur.execute("insert into soquestion values ('professor', 2, 4, 40, -7)")
- cur.execute("insert into soquestion values ('ferrari', 7, 50, 0, 48)")
- cur.execute("insert into soquestion values ('alaska', 10, 0, 1, 0)")
- cur.execute("insert into soquestion values ('gnat', -3, 0, 0, 0)")
- cur.execute("select * from soquestion")
- all = cur.fetchall()
- definition_list = ['word', 'big', 'expensive', 'smart', 'fast']
- def show_distinct(db_tuple, def_list=definition_list):
- minimum = min(db_tuple[1:])
- maximum = max(db_tuple[1:])
- if abs(minimum) > maximum:
- print db_tuple[0], 'is not', def_list[list(db_tuple).index(minimum)]
- elif maximum > abs(minimum):
- print db_tuple[0], 'is', def_list[list(db_tuple).index(maximum)]
- else:
- print 'no distinct value'
- for item in all:
- show_distinct(item)
Add Comment
Please, Sign In to add comment