415571	16561	how to combine these two queries into one? (multiple joins against the same table)	select w.*,   sum(t1.status = 1) as status_1_count,   sum(t1.status = 2) as status_2_count from workers w   left join tasks t1 on w.id = t1.worker_id and t1.status in (1, 2)  group by w.id order by w.id; 	0
504920	39431	sql tables subquery	select max(bar.timestamp), foo.foo_fluff   from foo  inner join bar           on foo.foo_id = bar.foo_id  group by foo.foo_fluff 	0.478772597438736
666595	17614	select all that are not in another table	select distinct    old.style_nbr, old.color_nbr  from    legacy_product_table old   left outer join marketing_product_table new     on (old.style_nbr + old.color_nbr) = (new.style_number + new.colour_number) where (new.style_number + new.colour_number) is null 	0.00019660114084528
1367101	31320	retrieving key attribute names of a given table	select       cols.table_name              , cols.column_name              , cols.position              , cons.status              , cons.owner from         all_constraints cons              , all_cons_columns cols where        cols.table_name = 'table_name' and          cons.constraint_type = 'p' and          cons.constraint_name = cols.constraint_name and          cons.owner = cols.owner order by     cols.table_name, cols.position; 	0
1492431	10463	return all fields and distinct rows	select b.* from (     select max(id) id, name, address     from table a     group by name, address) as a inner join table b on a.id = b.id 	0.00015492408355297
1518421	15217	how shall i get my friends of friends using mysql and php	select * from tbl_friendlist where mem_id in (select friend_id from tbl_friendlist where mem_id = 1). 	0.000858813471911701
1560626	33209	sqlserver: how to pair up ordered data for sequences of arbitrary (and unequal length)?	select      coalesce(a.fkid, b.fkid) fkid,      a.value as valuea,      b.value as valueb,      coalesce(a.sort, b.sort) sort from a full outer join b      on a.fkid = b.fkid      and a.sort = b.sort order by fkid, sort 	0.000455013887847955
1673802	17930	multiple max values in a query	select id, bdate, value  from myview  where (id, bdate) in     (select id, max(bdate)      from myview group by id) / 	0.0249978204243853
1974205	5356	how woud i join this query in one single sql statement?	select c.name, n.country_iso_code from companies c, companies_countries x, countries n where x.company_id = c.company_id and n.country_id = x.country_id 	0.727063904766841
2128280	33754	how do i count occurrences by day in sql?	select username, count(distinct(date)) as uniquedaysappeared from occurrences group by username 	0.000512273682002828
2294505	25391	only one expression can be specified in the select list when the subquery is not introduced with exists	select  issueno,          kendracode,          issuetime,          dateofissue,          p_motabags,          p_motaweight,          p_patlabags,          p_patlaweight,          p_sarnabags,          p_sarnaweight,          newbags,         oldbags,          transportername,          trucknumber,          drivername,          truckowner,         societycode,          rfs.* from    issuetosangrahankendra_soc s left join         (   select  paddymotaw,                      paddypatlaw,                      paddysarnaw,                      bagsmota,                      bagspatla,                      bagssarna,                     pc_id,                      sangrahankendraid,                      societycode,                     dm_id              from    receivefromsociety          ) rfs on rfs.dm_id =s.issueno where   kendracode='4403'  order by    societycode 	0.698205986774604
2558825	11202	how to detect if a string contains atleast a number?	select * from table where column like '%[0-9]%' 	0.00852489773679302
2819616	24744	how to count two fields by using select statement in sql server 2005?	select     sum(case col1 when 1 then 1 else 0 end) as count1,     sum(case col1 when 0 then 1 else 0 end) as count0 from table1 	0.0967791254392633
2868102	28767	create table by copying structure of existing table	select * into drop_centers_detail from centers_detail where 1 = 0 	0.00335220825624332
3053003	13714	filter rows on the basis of "first name" + "last name" in sql	select * from @test where (fname like '%' + @searchkeyword + '%') or (lname like '%' + @searchkeyword + '%') or (fname + ' ' + lname like '%' + @searchkeyword + '%') 	0
3090048	8880	prevent repeated row from returning in mysql	select distinct restaurant.name, restaurant.place from restaurant, type_stack where restaurant.id = type_stack.rest_id and type_stack.type = '0' and type_stack.type = '1' and type_stack.type = '2' limit 0 , 30 	0.00714913227236597
3361185	40432	problem with adding foreign key to table in mysql	select * from potovanja p where not exists     (select * from users where users.username = p.username) 	0.0253314133855105
3809375	29213	counting null data in mysql	select sum(case when x.status = 'single' or x.status is null then 1 else 0 end) as single,        sum(case when x.status = 'married' then 1 else 0 end) as married   from (select distinct                t.name,                t.status           from your_table t) x 	0.0598817074562608
4017079	12286	pervasive sql 10 join one table, onto another, onto another	select p.productid,           p.price,           x.max_eta      from products p left join porows r on r.productid = p.productid left join (select po.id,                   max(po.eta) as max_eta              from po po           group by po.id) x on x.poid = r.poid 	0.000859625456418079
4188564	39430	how do i map a derived property on a base class using nhibernate?	select ..., this_.damagecosttotal from assessment this_ order by this_.damagecosttotal 	0.0632570837366277
4271203	6336	sort db2 sql results by where clause	select *  from media  where media_title like 'query'      or media_title like 'query string'      or media_title like 'query string to search for'  order by case      when media_title like 'query' then 1     when media_title like 'query string' then 2     when media_title like 'query string to search for' then 3 end 	0.733678227234863
4365970	12551	finding blocking/locking queries in ms sql (mssql)	select * from sys.dm_exec_requests where db_name(database_id)='yourdbname' and blocking_session_id <>0 	0.386241572447634
4382379	2339	how to list the top 10 most duplicate rows?	select vote, count(*) from votes group by 1 order by 2 desc limit 10 	0
4789387	6372	adding an additional column to sql result set by using two que	select cr.communication_id, cr.consumer_id, cr.action_log_id,        cal.consumer_id, cal.tips_amount, cal.last_mod_time,        singleton.avg_tips from communication_relevance as cr join consumer_action_log as cal on cr.action_log_id=cal.action_log_id cross join (     select avg(tips_amount) as avg_tips     from consumer_action_log     join communication_relevance     on consumer_action_log.sender_consumer_id=communication_relevance.consumer_id ) singleton 	0.0206407347085958
4916233	32114	retrieving date format rows in mysql	select addeddate from status where addeddate <= now() - interval 29 day 	0.000935193011379486
5025556	22454	sql server - group records like archives by month	select count(id), datepart(year, dtcreated) as y, datepart(month,dtcreated) as mo      from taxessteps group by datepart(year, dtcreated), datepart(month,dtcreated)     order by 2 desc, 3 desc 	0.0841981377633771
5147257	26223	compare between two dates	select course.course_name, due_dates.course_id, due_id from course inner join due_dates on course.course_id = due_dates.course_id where now() between start_date and end_date; 	0.000399623750621585
5343296	40151	select only distinct values from duplicate rows	select client, totala, case when number = 1 then totalb else null end totalb, case when number = 1 then item else null end item  from (     select *, row_number() over(partition by client order by client) number      from clients  ) a 	0
5482704	6132	how can i compare different columns of different rows in the same mysql table (in php)?	select a.*,b.* from friends_requests a, friends_requests b  where a.requester = b.requestee 	0
5665299	35074	how to order by items based on data from two mysql tables?	select   a.name,   b.score,   concat(a.company, format(b.score * b.handicap, 0)) as sortfield from a,b where ... sort by sortfield 	0
5719185	35425	sql relationships	select bl.userid, b.name, t.estimate from batch_log as bl join batches as b     on b.id = bl.batch_id join task as t     on t.id = b.task_id where bl.userid = 123 	0.295268339235976
6949672	15313	sql query to find previous records	select trandate, location, badrec from     (     select pr.trandate, pr.location, pr.badrec,         row_number() over (partition by r.trandate order by pr.trandate desc) as sequence     from records r     join records pr on r.location = pr.location                     and r.trandate >= pr.trandate     where r.badrec = 1     ) x where sequence <= 4 	0.00114901101560209
6963545	8186	group by columns + count(*), how to get the average count for every combination?	select resolvedby, [count], ficategory, fisubcategory, fisymptom     , avg(z.count) over( partition by ficategory, fisubcategory, fisymptom ) as avgbygrp from    (         select resolvedby, count(*) as [count], ficategory, fisubcategory, fisymptom         from tcontact          group by resolvedby, ficategory, fisubcategory, fisymptom         ) as z order by z.count desc 	0
7026967	3078	unpivoting data from spreadsheet into data tables	select pk_2, "g1" as "pk_1", g1 as [value] from table union select pk_2, "g2" as "pk_1", g2 as [value] from table 	0.00121752788689135
7116508	17902	don't want the excess tag in my for xml path('td')	select empid "td/@id", empno "td"  from employees  for xml path('') 	0.0942011032810555
7237596	24813	manually escaping commas on sql statements	select count(*) from tablename where yuzeyko = '29,59'; 	0.73961760424989
7577902	9057	i would like to delete the row with 0 (zeroes)	select m.project, e.hours, e.resources from mytable m      inner join       emptable e      on (      m.employeeid = e.employeeid       and       e.employeeid = @employeeid      and      (e.resources <> '0' and e.hours>0)     )  order by e.employeeid 	0.212656362282815
7627124	24677	selecting with a limit, but also a limit on the amount of times a column can have a specific value	select distinct *   from   posts p1  where  user_id in (2,1000001) and not track_id = 34 and         (select count(*) from posts p2              where p2.user_id = p1.user_id and p2.id > p1.id and p2.track_id <> 34)          <= 1  group by          track_id   order by          id desc limit 5 	0
7914579	558	sql query - find row which exceeds cumulative proportion	select top 1   t1.itemno from   mytable t1 where   ((select sum(t2.proportion) from mytable t2 where t2.itemno <= t1.itemno) >= 0.35) order by   t1.itemno 	0.00487497132491516
7973150	24469	how to append html to the sql query	select top(@top) '<li><span><a href=''' + cu.url + '''>' + c.title + '</a></span></li>' from... 	0.0523704681461509
8105869	23959	calculating all values in column	select product_id, sum(quantity) as totalquantity, sum(cost) as totalcost from order_product where order_ordernumber = 1100 group by product_id 	0.000762798942610258
8438582	20646	mysql creating a top 10	select *, (price_shipping / abo_time + price / abo_time + abo_price) as month_avg  from db where model like '%iphone 4%' and model like '%16gb%' order by month_avg asc limit 10 	0.0179272108443694
8602298	16012	oracle - maximum year query error	select * from (     select add_months(sysdate,-2)dt from dual     union all     select add_months(sysdate,-1) from dual     union all     select add_months(sysdate,2)from dual     union all     select add_months(sysdate,3) from dual     order by trunc(dt,'year') desc, trunc(dt,'month') asc ) where rownum = 1 	0.121645075522602
8779585	21570	select random rows from mysql table	select * from table order by rand() limit 10; 	0.000362340235820891
8829354	14568	sql combine 2 queries with join	select   count(*) as count, g.id, g.name, g.color from     gangs g join turfs t on t.gang = g.id where    city = '$city' group by g.id, g.name, g.color 	0.188697634140062
8899327	13507	optimizing a sql query finding entries that do not exist in table	select distinct m.name from @mytable m left outer join job_log j on j.name = m.name and j.start_date > @startdate and j.start_date < @enddate where j.name is null 	0.00707059380591247
8930791	33937	populate dataset with table names from stored procedure	select *,'mytablename1' as [tablename] name from mytablename1    select *,'mytablename2' as [tablename] name from mytablename2 	0.00416933784156452
9308867	6337	mysql group_concat with sums also inside	select concat('{', group_concat(c1), '}') from (   select concat('"', type, '":', sum(amount)) c1 from t1 group by type   ) t 	0.369700608226997
9566554	23471	how to add a single column php/mysql	select sum(course_unit) as total from your_table; 	0.00213270956633489
9834758	1837	how to use two joins on the same column	select teams1.name as team1, teams2.name as team2, matchs.id, matchs.date, matchs.time from matchs     inner join teams as teams1         on teams1.id=matchs.team1     inner join teams as teams2          on teteams2ams.id=matchs.team2 	0.00338269200364031
10027409	18137	mysql can't join two tables columns into one show	select show_users.id, count(distinct `table1`.id) as sum_fields , sum(`table2`.count) as count_all 	0.000243041790532479
10199950	2775	count number of times value appears in particular column in mysql	select email, count(*) as c from orders group by email 	0
10283363	22801	mysql left joining same table twice	select     u.first_name,     u.last_name,     u.email,     (         select             sum(e1.total_vacation_hours_earned)         from             ee_calendar_events as e1         where             u.user_id = e1.sched_user_id     ) as vacation_hours_earned,     (similar) as absent_hours from     ee_all as u where     u.user_id = 23 	0.027375184945205
10391235	1612	sql to group based on the counts of a column	select distinct   num_of_statuses = count(*),   count           = count(*) over (partition by count(*)) from atable group by id 	8.11419850784889e-05
10541830	35386	query to get last message only from all users	select a.from_user_id, a.message from table1 a where a.datetime = (select max(datetime) from table1 x where x.from_user_id = a.from_user_id) 	0
10645194	39865	sql sum a field grouped by same identifier in two different columns	select p.player id,        (select sum(qty) from tbl where win = p.player) win,        (select sum(qty) from tbl where lose = p.player) lose from     (select distinct win player from tbl     union     select distinct lose from tbl) p 	0
11238630	24278	mysql:while using group_concat & count	select  user_name,  group_concat(user_week) as user_weeks,   group_concat(user_reward) as user_rewards from (   select    user_name,    week(cpd.added_date) as user_week,    count(cpd.result) as user_reward   from cron_players_data as cpd    where    cpd.player_id = 81 and    cpd.result = 2 and    cpd.status = 1   group by user_week ) as temp group by user_name; 	0.586470033187536
11579946	37505	only show hours in mysql datediff	select timestampdiff(hour, start_time, end_time)             as `difference` from timeattendance where timeattendance_id = '1484' 	0.00065558187910577
11636613	35123	mysql - select all unless query	select  oc_ieentry,oc_sysitem,oc_item,oc_itemdesc,oc_purchasedate,oc_url  from catalog  where (oc_purchasedate >= date_sub(current_date, interval 21 day))  and (oc_ieentry not like 1)  order by oc_item asc 	0.104964353366509
11966465	8446	select distinct values columna while columnb = value1 and columnb = value2	select content_id from tags where `name` in ('banana', 'orange') group by content_id having count(distinct `name`) >= 2 	0.282210613398918
12073592	10865	multiple count statements in 1 sql query without subselect	select user.id, user.name, count(distinct value_type_1.id),count(distinct value_type_2.id) from user    left join value_type_1 on user.id = value_type_1.user_id    left join value_type_2 on user.id = value_type_2.user_id group by user.id, user.name 	0.704550366859792
13077522	32696	select rows missing from link table	select contacts_options_full.contactid, contacts_options_full.optionid, options.serviceid from (   select contactid, optionid   from (select optionid from options) o   cross join   (select distinct contactid from contactoptions) co ) contacts_options_full left join contactoptions on contacts_options_full.contactid = contactoptions.contactid and contactoptions.optionid = contacts_options_full.optionid join options on contacts_options_full.optionid = options.optionid where contactoptions.serviceid is null order by contacts_options_full.contactid, contacts_options_full.optionid 	0.000588193126630782
13187546	34144	show me the index on the table in oracle	select index_name   from all_ind_columns  where table_name = 'the_table'    and column_name = 'the_column'    and index_owner = 'the_owner'; 	0.086408553264145
13807905	10766	mysql statement search all tables for one specific column?	select * from information_schema.columns  where lower(column_name) = 'discount' or lower(column_name) = 'discounts'; 	0.00049570598489536
13820066	39730	mysql join with grouping and ordering	select c.*, (select preview   from images img   where img.cid = c.cid   order by img.id desc  limit 1) as preview from categories c 	0.657760182509558
14107013	4579	compare 2 tables in sql	select * from a1 where not exists (select * from a2 where a2.id = a1.id) 	0.00682777195551557
14243386	4592	for each row from select insert multiple rows into one table	select    identity(int, 200, 1) idtable_3,    t1.idtable_1,    t2.idtable_2,    case t2.column when 'x' then t1.x                   when 'y' then t1.y                   when 'z' then t1.z end value into table_3 from table_1 t1   cross join table_2 t2 	0
14771164	36557	mysql writing image blob to disk	select   data_column from   table1 where   id = 1 into dumpfile 'image.png'; 	0.723442624592362
14984782	20811	how do i get top 5 score in mysql	select s.* from student as s   join     ( select distinct score       from student       order by score desc           limit 5     ) as lim     on s.score = lim.score  order by s.score desc ; 	0.000653281489110117
15360788	10795	need mysql idiom for checking whether string contains any of a set of characters	select id, name from mytable  where name not rlike '[;.<>#$!]'; 	0.000874249866540926
15434503	39195	adding zero when concatenating year and month	select convert(varchar(4), s_yr)     + right('0'+ convert(varchar(2), s_mnt),2) as year_month 	0.000447458800389394
15449347	26068	inner join? pulling info from 2 tables - webmatrix/razor	select ownerinfo.firstname, ownerinfo.lastname  from ownerinfo inner join propertyinfo on propertyinfo.ownerid = ownerinfo.ownerid where propertyinfo.propertyid='@0' 	0.00225053178451816
15478974	38793	loop through mysql table and output in particular order with php	select              *         from              table         where             spec=:spec         order by car_name=:user_car desc, car_name asc 	0.0949787477218333
15815961	13791	how to only get non numeric part of column out	select substring(tcode,patindex('%[^0-9]%', tcode),1) from codes where patindex('%[^0-9]%',tcode) > 0 	0
16253174	24455	swap columns value in output based on certain condition using sql server	select (case when symbol='<' then [to]  else [from] end)as [from],(case when symbol='<' then [from]  else [to] end)as [to] from temp 	0
16447516	27150	unpivot a columns to generate rows	select val from   (     select col1 = '1', col2 = '2', col3 = '3' ) a unpivot  (    var for col in (col1, col2, col3) ) as unpvt 	0.00220498358829498
17466751	27699	count of number of records in each time interval with mysql	select     count(date_action) as count,     case          when minute(date_action) between 0 and 14 then '00'         when minute(date_action) between 15 and 29 then '15'         when minute(date_action) between 30 and 44 then '30'         when minute(date_action) between 45 and 59 then '45'     end as intervals from     clients where     hour(date_action) = 09     and day(date_action) = 15     and month(date_action) = 07     and year(date_action) = 2013     and rep_id = 28 group by intervals 	0
17570676	14849	mysql select group by count(*) union into delimited string?	select group_concat(concat_ws(',', playerid, r1, r2) separator ';') from (   select   playerid, sum(rank=1) r1, sum(rank<5) r2   from     result   group by playerid ) t 	0.0226988318649734
17582050	818	how can i select rows from a table when i max(cola) and group by colb	select x.*       , (scorea+scoreb)/2 avg_score     from scores x     join       ( select player, max((scorea+scoreb)/2) max_avg_score from scores group by player) y       on y.player = x.player      and y.max_avg_score = (scorea+x.scoreb)/2; 	0.00133540722071522
17786296	21838	ms access - link to query in another access database	select [remotequeryname].* from [remotequeryname] in 'c:\remotedatabase.mdb' 	0.281566166282936
17934887	29554	formatting decimal with sql	select proc_p,right('000'+cast(cast((cast(proc_p as decimal(4,0))/100) as decimal(4,2)) as varchar(5)),5) from test 	0.767253309597963
17958247	22082	only filter out what some parameters have in comon with sql	select   items.itemid, group_concat(itemrelation.itemrelto) as itemrelto, items.catid, items.title, items.image, items.desc, items.timestamp from items inner join itemrelation  on items.itemid = itemrelation.item where itemrelto in (30,31) group by itemid having count(items.itemid) > 1 	0.145162427130473
18412557	22587	return all records of non-given id if just one of those records matches the given id of another field	select * from offers where listing_id in (select listing_id from offers where user_id = 1) 	0
18634537	33449	how to pass a integer array to not in conditions in postgresql?	select fields from table where fieldno <> all(xfields); 	0.250044038186747
18862004	39075	sql query to filter a table using another table	select * from datatable where id in (   select dt.id   from datatable dt     join filtertable ft on ft.name = dt.name            and ft.value = dt.value   group by dt.id   having count(*) = (select count(*) from filtertable) ) 	0.00590128839583362
19909230	19803	sql - select * from table order by	select name from tbl group by name order by  case when name = 'bgin' then 0      when name = 'mid' then 5      when name <> 'mid' and name <> 'bgin' then 1 end, name 	0.0169957752802059
19983334	35455	need to find value in one column and then return value from another column	select t.avalue,        case t.avalue          when t.actualcolumn1 then t.relativecolumn1          when t.actualcolumn2 then t.relativecolumn2          when t.actualcolumn3 then t.relativecolumn3          when t.actualcolumn4 then t.relativecolumn4        end as rvalue from t 	0
20061274	740	how to count number of unique (by 3rd field in a whole set) ids by type	select   type, count(*) from     (select acc_fk, type from t1 group by acc_fk) t group by type 	0
20193359	577	sqlite count members in a group	select gu1.group_id_foreign      , count(*) ttl    from group_participants gu1   join group_participants gu2     on gu2.group_id_foreign = gu1.group_id_foreign  where gu1.user_id_foreign = 1  group      by gu1.group_id_foreign; 	0.067489095439085
20333830	24907	sql update same table	select legacyfullpathnme into newtable from oldtable group by legacyfullpathnme; 	0.0176363573018365
20494022	20529	selecting data between dates in sql	select status,        startdate,        lead(startdate, 1,null)           over (order by startdate)          as enddate from t order by startdate 	0.00120928691552025
21043888	33035	mysql select all rows meeting the first and second lowest values?	select * from test where `value` in (    select * from (       select distinct `value`        from test        order by `value`        limit 0,2    ) as t ) 	0
21200862	32211	get records for each person's each day's min datetime	select a1.* from accesscards a1 join (select name, min(entrydates) mindate       from accesscards       where name != ''       group by name, date(entrydates)) a2 on a1.name = a2.name and a1.entrydates = a2.mindate 	0
21538049	2328	hive date format handling	select unix_timestamp(regexp_replace('mon 2014-01-03 13:00:00 +gmt0000','gmt',''),                       "eee yyyy-mm-dd hh:mm:ss z") as unixtime from reqtable; 	0.768998964626258
22002693	27563	how to delete non duplicate rows in mysql?	select e.ssn, e.fname, e.lname, d.dependent_name, d.sex, d.relationship  from employee e join      dependent d       on e.ssn = d.essn join      (select d.essn, count(*) as cnt       from dependent d       group by d.essn       having cnt >= 2      ) d2      on e.ssn = d2.essn order by e.ssn; 	0.000801086156821696
22016334	1599	mysql and php: select all fields from the same date	select  id,  date,  site,  url from links  where publish = "yes"  and    date = ( select date from links where date < '2014/02/25' order by date desc limit 1 )   and category!= 'adult'  order by date desc, clicks desc limit 200 	0
22233567	25612	get result in a one hour interval	select x.*   from my_table x   join      ( select max(dt) max_dt          from my_table         group by date(dt),hour(dt)     ) y    on y.max_dt = x.dt; 	9.7715888911588e-05
22250125	7195	how to use alias name of inner query as a column to get record that have no data or is null in sql query?	select sq.subcategoryname,     sq.subcategoryid,     sq.imagename from (     select subcategoryname,         subcategoryid,       (select top (1) image          from postimage         where (postdesignid like (                                     select top (1) postdesignid                                       from postdesign                                      where (subcategoryid = sc.subcategoryid)                                            or (subcategoryid2 = sc.subcategoryid)                                   )                )        ) as imagename    from subcategory as sc  ) as sq where sq.imagename is not null 	0.00156911009581837
22687491	19686	after joining three query not getting proper result in sql server	select sum(status_receved) as receved, sum(status_parked) as parked, sum(status_requested) as requested from (select case when (status = 0) then 1 else 0 end as status_receved, case when (status = 2) then 1 else 0 end as status_parked,  case when (status = 3) then 1 else 0 end as status_requested  from transaction_tbl where locid = 6 and status in (0,2,3)) a; 	0.739949582419036
22983055	32258	t-sql select values from the end of a string which are between 2 characters	select reverse(substring(reverse(colname),2,charindex('a',reverse(colname),2)-2)) from yourtable 	0
23006307	4280	how to have two nested queries inside one select statement?	select tp.l# from truck t inner join trip tr on tr.reg# = t.reg# inner join tripleg tl on tl.t# = tr.t# and tl.departure = 'melbourne' where t.reg# = 'pkr768' 	0.0948820143819509
23519408	12122	select all for the last projetid entered	select  * from projetstaches      where projectid= (select max(projectid) from projetstaches) 	4.76294811505e-05
23668656	13168	how to get month-to-date excluding today (month to yesterday?)	select coalesce(sum(subtotal),0) from dbo.dr_trans where transdate >= cast(getdate() - day(getdate()) + 1 as date) and       transdate < cast(getdate() as date); 	0
23809815	25370	finding the web page which is calling a sp	select session_id, client_net_address, hostname, program_name from      sys.dm_exec_connections c  inner join     sys.sysprocesses s on      c.session_id = s.spid where      session_id = @@spid 	0.583210180463452
24199265	29303	how i can natural sort in mysql? i have followed table:	select name,  convert(replace(name, substring_index(name, reverse(convert(reverse(name), signed)), 1), ''),signed) as t, substring_index(name, reverse(convert(reverse(name), signed)), 1) as d from sortnum order by d, t asc; 	0.126665144507871
24927245	23963	simplifying mysql query - 2 queries into 1	select distinct t2.word from table t1  inner join table t2 on t2.entity=t1.entity where t1.word="blue"; 	0.356555378704614
24933415	14672	how to filter table according to data in postgres?	select t.tablename, c.reltuples from pg_tables t join pg_class c on c.relname = t.tablename where schemaname = 'public' and reltuples > 0; 	0.00128944319989718
24978304	41238	use the result of the mysql select query as a where condition in the same query	select if(`key` < 900, `key`, null) `key` from ( (     select max(  `peg_num` ) as  `key`      from  `list`      where  `list_id` =1     ) as  `derivedtable` ) 	0.00696511757007485
24989365	9412	sorting a string numerically in sql server	select * from yourtable order by cast( substring(yourcolumn, 6,len(yourcolumn)) as int) 	0.323789043638024
25262853	22421	group by on same table and include all data like names	select name,         clientid,         sum(case when status = 2 then 1 end) as status_2,        sum(case when status = 4 then 1 end) as status_4 from your_table group by name,          clientid 	6.4723711828654e-05
25291161	12182	two queries, duplicate results	select      sp.room_type_id,      sp.slot_price,      sp.slot_time,      sp.slot_date,      sa.slot_avail_clean,      sa.slot_avail_noclean    from rn_slots_prices       sp join rn_slots_availability sa on   sa.hotel_id     = sp.hotel_id     and   sa.room_type_id = sp.room_type_id and   sa.slot_date    = sp.slot_date where       sp.hotel_id  =  5           and      sp.slot_date = '2014-08-12' and      sp.slot_time = '00:00:00' 	0.0112831924392922
