I have a list of prodcut archive and I'm using dotrine and symfony,I hoped to show list of archive product :
$query = Doctrine::getTable('Product')
->createQuery('a')
->select('a.created_at, YEAR(a.created_at) as year, MONTH(a.created_at) as month')
->groupBy('year, month')
->orderBy('a.created_at DESC')
->setHydrationMode(Doctrine_Core::HYDRATE_ARRAY)
->execute();
So I hope to change the query so when is more than 1 year old it should group added Product by year?
Edit :
I added this but I guess it's dosn't work with doctrine 1 :
->andWhere("year <= DATE_ADD(CURRENT_DATE(), 1, 'YEAR')")
I get this error :
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1, 'YEAR')
I don't think you can define different groupBy clauses in a single select. You can, however, do one of the following:
(1) Build 2 independent queries - one for >1 year and the other for <1 year. Then, since you are hydrating to arrays anyway merge your arrays using array_merge.
(2) Use an SQL UNION to merge the results of your two queries. Unfortunately, doctrine2 does not support UNION, so you need to fall back to standard SQL (see here)
The only open point left is that, if you want the results of both queries to look the same, you need to add a default value for the month in your "older than 1 year" query.
Related
So I have this dummy csv file:
year, value
2001,А
2001,B
2002,A
2021,B
2022,A
2022,B
I've ingested it using GetFile processor and now I am trying to create few files out of this one
according to a value of "year" column.
So I am using QueryRecord processor and I've created a couple of attributes in this processor such as:
year_2001: select * from flowfile where year = 2001 (also I've tried year = '2001')
year_2022: select * from flowfile where year = 2022
But when I start this processor I am getting some huge error I don't understand. It is too huge to copy here but basically it says that my SQL statement ain't valid. When I remove "where" clause it works fine, so apparently it is the "where" clause that I don't seem to get right.
Thank you beforehand.
UPD. I've found this article and it seems like I do exactly same as example shows.
Ok, I have figure this out. Apparently naming my column "year" wasn't such a good idea. Seems like it conflicted with year function or something. So I just enclosed year in quotes and it worked.
So the correct sql statement will be
select * from flowfile where "year" = '2001'
I'm trying to group results by Year, Month, Day for output.
2019
February
Day
I'm not sure what I'm doing wrong here, and wonder if it is an MS Access issue. The following code produces a too few parameters error.
<cfquery name="nchklist" datasource="#fds#">
SELECT year(chkdate) AS Year, month(chkdate) AS month, day(chkdate) AS day, vcheck
FROM vchk
where vid = '#vid#' and final = 1
ORDER BY year, month, day
</cfquery>
<cfoutput query="nchklist" group="year">
<cfoutput group="month">
#monthAsString(month)#
<cfoutput group="day">
View : DateFormat(chkdate, 'dddd - mmmm d, yyyy')#<br>
</cfoutput>
</cfoutput>
</cfoutput>
Update:
It's been years since I've used Access, so my knowledge is kind of hazy, but I'm starting to remember it had limitations with the ORDER BY clause. Unlike a true DBMS, it wasn't smart enough to allow ordering by column aliases. I don't know if that's changed in recent versions, but ... like I mentioned earlier, you should try ordering by the original expressions - NOT the aliases:
ORDER BY year(chkdate), month(chkdate), day(chkdate)
As an aside, CF isn't a great sql debugging tool. It communicates with databases indirectly, usually via JDBC drivers. That process often returns far more generic error messages than you'd receive than from using standard database tools. Whenever you encounter a cryptic error like that, best to run the sql query directly within the database, hard coding parameters as needed. Doing that probably would've given you a less cryptic error message, or at least indicated the ORDER BY clause was the problem.
As mentioned in comments, that error may indicate a misspelled column name. It can also occur when a reserved word is used as column name or alias. Notice your query uses functions named Year, Month and Day? Those are reserved words in Access. That's probably the cause of the error. Try changing your column aliases to non-reserved words, for example TheYear, TheMonth, TheDay.
Assuming MS Access supports ordering by column aliases, try the query below:
SELECT year(chkdate) AS TheYear
, month(chkdate) AS TheMonth
, day(chkdate) AS TheDay
, vcheck
FROM vchk
WHERE vid = <cfqueryparam value="#vid#" cfsqltype="cf_sql_varchar">
AND final = 1
ORDER BY TheYear, TheMonth, TheDay
Note: Even with MS Access, queries should always use cfqueryparam on all input parameters.
Crosstab report works 99%.
About 20 rows, all but one are ok.
5 columns - Company Division.
The rows are things like cost, revenue, revenue 2, etc.
All the rows that work have three attributes I'm using to select them:
Fiscal Year
Period
Solution.
The problem is there is table that lists an YTD rate for each period. This table is not Division Specific; it's company wide.
All the tables are linked to the accounting period table that has fiscal year and period. So the overall query limits data to fiscal year (?pFiscalYear?) and period <= ?pPeriod?, based on prompt page results.
The source table has this:
FY_CD PD_NO ACT_CURR_RT ACT_YTD_RT
2018 1 0.36121715 0.36121715
2018 2 0.32471476 0.34255512
2018 3 0.25240906 0.31210183
2018 4 0.33154745 0.31925874
Note the YTD rate is not an average of any of the other numbers.
When I select the ACT_YTD_RT, as a row, I want the ACT_YTD_RT that matches the selected period.
What I get is the average if I set the aggregation to average or the lowest if I set it to other aggregations. So sometimes, it looks right (if I run for period 1,2,3, as the rate kept falling), and sometimes it's wrong (period 4
returns .3121 instead of .3192).
I've tried a number of different methods and can generate garbage data (totals, min, max, average) and crossjoins but can't figure out how to get the value I'm looking for.
I want YTD_RT where fiscal year =?pFiscal? and period = ?pPeriod?.
I tried a straight if then clause:
if (sourcetable.fiscalYear = ?pFiscalYear?) and (sourcetable.Period = ?pPeriod?) then (ACT_YTD_RT)
but I get an error like this:
'ACT_YTD_RT' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. (SQLSTATE=42000, SQLERRORCODE=8120)
If I create another query that generates the right response and try to include it, I get a crossjoin error that the query I'm referencing is trying to crossjoin several other items in the crosstab query.
A union doesn't work (different number of columns).
Not sure how a join would work since the division doesn't exist in the rate table.
I maybe could create a view in the database that did a crossjoin of the division table and the rate table, add that to the framework and then I wouldn't have a crossjoin since the solution would be in the rate "table" (really view), but that seems wrong somehow.
If I could just write a freaking parameterized query direct to the database I'd be done. But in Cognos 11 crosstabs I can't find a place for a SQL query object. And that shouldn't be necessary.
I've spent hours and hours chasing this in circles.
Anybody have any ideas?
Thanks
Paul
So the earlier problem was that this:
if (sourcetable.fiscalYear = ?pFiscalYear?) and (sourcetable.Period = ?pPeriod?) then (ACT_YTD_RT)
Generated an error like this:
'ACT_YTD_RT' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. (SQLSTATE=42000, SQLERRORCODE=8120)
To fix the above, I had to add a cross join of the division table and the rate table as a view in the database. Then add that to the framework. Then build the data item this way:
total (
if (sourcetable.fiscalYear = ?pFiscalYear?) and (sourcetable.Period = ?pPeriod?) then (ACT_YTD_RT)
)
And now the "total" provides the missing group by. And the crossjoin in the database provides the division information so the crosstab is happy.
I still think there should have been an easier way to do this, but I have a functioning hammer at the moment.
I am trying to get all the orders under user. I am using below XPTAH query.
/jcr:root/home/users/a/admin/commerce/orders//element(*)[#orderId] this result below records :
/home/users/a/admin/commerce/orders/order-2014-Apr-12
/home/users/a/admin/commerce/orders/order-2015-Apr-15
/home/users/a/admin/commerce/orders/order-2015-Apr-13
Now i have requirements that order should be in the sorted order as per booked(that i am looking for) , Other is i will have dynamic parameter which will I pass through the method in which i have the XPTH query executed e.g. 6 or ALL . 6 will display the last 6 months order only (that i am looking for). For all orders i can use the query with sort condition /jcr:root/home/users/a/admin/commerce/orders//element(*)[#orderId] order by #orderPlaced descending . I have orderPlaced property of Date type 2014-04-12T17:05:35.085+05:30. So want to put condition result will include last 6 months.
Thanks
try the query-debugger located at /libs/cq/search/content/querydebug.html
it shows the query in different formats including xpath-syntax. for instance you get the ordering syntax by running this url:
querydebugger
This solved my problem :
type=unstructured
path=/home/users/a/admin/commerce/orders
path.flat=true
orderby=#orderPlaced
orderby.sort=desc
1_relativedaterange.property=orderPlaced
1_relativedaterange.lowerBound=-6M
1_relativedaterange.upperBound=0
I got a problem with this linq query:
from PersistedFileInfo fi in m_Database
from PersistedCommit commit in m_Database
where commit.FileIDs.Contains( fi.ID )
where fi.Path == <given path>
select new Commit( m_Storage, commit );
As you can see, every PersistedCommit contains a Collection<int> called FileIDs which connects it to its PersistedFileInfos. I want to select all previous commits of a specific fileInfo (which is identified by its path).
I have about 800 PersistedFileInfos and 10 PersistedCommits. The query takes about 1.5 seconds - which is in my opition far too long. The contructor of the Commit-object saves only the two given arguments - so there is no timeloss, here.
My question:
Can this query be rewritten to perform better - or is it a db4o problem (use a SODA query instead)?
Please check if your NQ is indeed optimized (see here). If not then your best bet is to translate this into SODA query yourself.
Goran