query-builder

Laravel 4 Query Builder - groupBy Max Date

我的未来我决定 提交于 2020-01-04 02:00:12
问题 little query question, I have table: id | user_id | paper_update ------------------------------ 1 | 1 | 30-5-2011 2 | 2 | 30-5-2012 3 | 3 | 30-5-2012 4 | 1 | 30-5-2013 5 | 2 | 30-5-2013 6 | 3 | 30-5-2014 7 | 4 | 30-5-2014 8 | 5 | 30-5-2014 9 | 5 | 30-5-2015 10 | 5 | 30-5-2016 11 | 1 | 30-5-2010 ------------------------------- What I'm looking to do is to select only the records where paper_update is max between records with the same user_id , actually I want to group by the user_id in order

Runtime SQL Query Builder

拟墨画扇 提交于 2020-01-02 22:01:15
问题 My question is similar to Is there any good dynamic SQL builder library in Java? However one important point taken from above thread: Querydsl and jOOQ seem to be the most popular and mature choices however there's one thing to be aware of: Both rely on the concept of code generation , where meta classes are generated for database tables and fields. This facilitates a nice, clean DSL but it faces a problem when trying to create queries for databases that are only known at runtime . Is there

How to injecting custom columns in Laravel query builder

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-02 14:32:00
问题 I got a query with many joins, wheres, ect. And what I need to do is insert some maths into each result set as it will be feeding either a csv export or be displayed on page. Can later on even be sent back as API, so what I really want to do is prepare the data once, and then use it where ever. $result = DB::table('a') ->join('b') ->where('c') ->orderBy('d') ->select('e'); if ($paginate) { $query->paginate(); } else { $query->get(); } So the question is, can I somehow iterate through my

symfony2 doctrine select IFNULL

故事扮演 提交于 2020-01-02 01:02:27
问题 Ok i have this code: SELECT IFNULL(s2.id,s1.id) AS effectiveID, IFNULL(s2.status, s1.status) AS effectiveStatus, IFNULL(s2.user_id, s1.user_id) as effectiveUser, IFNULL(s2.likes_count, s1.likes_count) as effectiveLikesCount FROM statuses AS s1 LEFT JOIN statuses AS s2 ON s2.id = s1.shared_from_id WHERE s1.user_id = 4310 ORDER BY effectiveID DESC LIMIT 15 And i need to rewrite it to querybuilder. Something like that? $fields = array('IFNULL(s2.id,s1.id) AS effectiveID','IFNULL(s2.status, s1

doctrine2 - querybuilder, empty parameters

大憨熊 提交于 2020-01-01 19:00:13
问题 what can i do if the parameter has no value? my query: $query = $this->_em->createQueryBuilder() ->select('u') ->from('Users', 'u') ->where('u.id = ?1') ->andWhere('u.status= ?2') ->setParameter(1, $userid) ->setParameter(2, $status) ->getQuery(); return $query->getResult(); if theres no $status, then it doesnt display anything. i tried putting a condition before the query to check if its null but what value can i set $status iif theres no status set 回答1: The query builder is exactly there

laravel query php how to get max value within a range

▼魔方 西西 提交于 2020-01-01 10:28:50
问题 hello how do i get the max value of scores, where column ID range starts at 3-5 example table I want to get the max value of scores, where column ID ranging from 3-5 , please help, what I have done so far: $max_scores_table= DB::table('scores_table') ->where('id', '>', 2) ->max('score'); another problem is when i have a decimal points in the table when I used the max() function it gets the ID=5, which has a Score of 4.5, instead of ID=4 with a value of 4.6, tnx in advance 回答1: Try to use

doctrine 2 - query builder conditional queries… If statements?

半世苍凉 提交于 2020-01-01 09:43:18
问题 My query is doctirne 2. i have a status field in users, private or public. i want to be able to run this query and display all comments where status= public and private only if userid = current logged in user id(which i know, $loggerUserVarID) $q = $this->em->createQueryBuilder() ->select('c') ->from('\Entities\Comments', 'c') ->leftJoin('c.users', 'u') ->where('status = public') ??? display all public comments but private if it belpongs to the logged in user.? ->setParameter(1,

How do I get a “select count(*) group by” using laravel eloquent

让人想犯罪 __ 提交于 2020-01-01 08:33:22
问题 I would like to execute the follow sentence using laravel eloquent SELECT *, count(*) FROM reserves group by day The only solution occurs to me is to create a view in the DB, but I am pretty sure there is a way to do it in laravel way. 回答1: You could use this: $reserves = DB::table('reserves')->selectRaw('*, count(*)')->groupBy('day'); 回答2: As you wish to do it with Laravel Eloquent I assume you have a model name Reserve . In this case you can use this $reserve = Reserve::all()->groupBy('day'

Web based visual query builder

怎甘沉沦 提交于 2020-01-01 04:23:25
问题 I am after a visual query builder along the lines of http://ajax.easyquerydemo.com/. I am using ASP.NET but MVC so would rather something that is not WebForms based like the one in the link. If anyone knows of similar tools that are largely platform agnostic please let me know. 回答1: Was looking for the same sort of thing, came across this http://devtools.korzh.com/query-builder-component/ which looks very interesting to me... 回答2: Activer query can do all the thing you want: http://www

Query for retrieving data records for a specific date range in Laravel 4

好久不见. 提交于 2020-01-01 03:44:28
问题 I have a table having record_date and corresponding amount field.I was trying to retrieve total amount grouping by the months of the date . I am new to laravel and in normal php i would have used the following mysql query --> SELECT MONTH(record_date),YEAR(record_date),SUM(amount) FROM table_name WHERE record_date > DATE_SUB(now(), INTERVAL 6 MONTH) GROUP BY YEAR(record_date), MONTH(record_date); This simply returns the total amount collected for last 6 months each grouped by the month and