I would like to display the data, based on the date: for eg
Currently, the code I have come up with is this:
Jade:
ul
li(ng-repeat="history in vm.alertHistoryData | orderBy:'alert-modified-date':true ")
h4
| {{ history["alert-modified-date"] | date:"MMM d yyyy" }}
p
| {{ history["alert-modified-date"] | date:"h:mm:s a"}}
div
p
| Priority: {{ history.priority }}
| State: {{ history.state }}
which gives me result in this format:
May 3
data
May 3
another data
May 2
data
May 1
data
Is there a way to group by the date as per the date. I tried using groupBy filter of Angular js , but it doesnt work
li(ng-repeat="history in vm.alertHistoryData | orderBy:'alert-modified-date':true | groupBy: 'alert-modified-date")
Please help.
Related
I have a database, with a bunch of different columns. Let's say it looks like this:
TABLE: dbtable
__________________________________
| onecolumn | id | twocolumn |
|---------------------|------------|
| some | 1 | matchthis |
| random | 2 | dontmatch |
| thing | 3 | matchthis |
| here | 4 | dontmatch |
|__________________________________|
I also have a Node.js program (using Sequelize), that is supposed to sort through the dbtable table, and find the row that has the highest ID value, as well as has twocolumn equal "matchthis". (all of these values are examples).
The code looks something like this:
const rel = await dbtable.findOne({
where: {
twocolumn: req.params.twocolumn // Url param that equals "matchthis"
},
order: Sequelize.fn('max', Sequelize.col('id')),
});
However, instead of returning {"onecolumn": "thing", "id": "3", "twocolumn": "matchthis"}, it returns this error:
SequelizeDatabaseError: Expression #1 of ORDER BY contains aggregate function and applies to the result of a non-aggregated query
I'm not very good with Databases, and i can't seem to figure out what is going on.
Your query doesn't contain a GROUP BY clause making it a 'non-aggregated query' as the error suggests, making it incompatible with ordering by an aggregating function (MAX()).
You can order directly on the id column instead.
const rel = await dbtable.findOne({
where: {
twocolumn: req.params.twocolumn
},
order: [
[ 'id', 'DESC' ]
]
});
I'm trying to make a row visible based on two parameters.
ParameterA is a string.
ParameterB is a string.
Dataset looks like this:
Product | Warehouse | Quantity
1000 | A | 100
1000 | B | 100
Subtotal | | 200
1001 | A | 200
1001 | B | 200
Subtotal | | 400
1002 | A | 500
Subtotal | | 500
Parameter A shows (2) or hides (1) the individual warehouse entries, just leaving the subtotal.
For Parameter B, it returns a 0 if there is only one warehouse with stock for a product, and a 1 if there is more than one warehouse with stock for that product.
For the 'subtotal rows', I would like it to show if Parameter A wants to hide the warehouse entries, but obviously make sure the row is visible if there is only one product for that warehouse. Otherwise, Product 1002 won't show with the 'hide individual warehouse entries' option.
My attempt looks like this:
=IIF(Parameters!ParameterA.Value = "2" & Parameters!ParameterB.Value = 1,True,False)
This generates the below error:
The Hidden expression for the tablix 'Tablix2' contains an error:
operation '&' is not defined for string "2" and type 'Object()'.
Any ideas how to get the desired result would be appreciated.
In VB.Net, '&' is used for concatinating two strings and for logical-AND operator we simply use 'and'..
These are two entirely different keywords.
Here, you are trying to use '&' for logical-And operation which causes the error. Correct expression should be like this:
=IIF(Parameters!ParameterA.Value = "2" AND Parameters!ParameterB.Value = 1,True,False)
DATABASE:
id | name | // ...
====================
1 | London |
2 | Paris |
3 | Moscow |
4 | New York |
// ...
TEXT:
This is a big city. I live in this town.
I like the name of city. 'New York' is very cool.
However, I have to go to Moscow this summer.
// ...
There are a lot of records in the database.
Text is written in various languages.
I would like to get the records related to text.
In this case, I would like to get the records of 'New York' and 'Moscow'.
I am using a Doctrine2 ORM and DQL.
And my database is usually mysql.
Is it possible to achieve this by using the DQL?
UPDATE
City Entity : id, name, population date_created etc...
id | name | population | // ...
====================================
1 | London | 1,2448,3938|
2 | Paris | 1,8759,4844|
3 | Moscow |12,8450,3748|
4 | New York | 8,4795,8558|
// ...
Article Entity : id, body, author, date_created etc...
id | body | // ...
============================================================
1 | This is a big city. I live in this town. |
| I like the name of city. |
| 'New York' is very cool. |
| However, I have to go to Moscow this summer.|
| // ... |
2 | We bought a house in London. //... |
3 | I go to Canada this weekend. //... |
4 | Weather in Africa today is too bad. //... |
// ...
The text is good whether it get from a file or a database.
public function findOneById($id)
{
$query = $this->getEntityManager()->createQuery('
SELECT a, u
FROM MyArticleBundle:Article a
LEFT JOIN a.author u
WHERE a.id = :id
')
->setParameter('id', $id);
return $this->try_catch($query);
}
or
$article = file_get_contents('example.txt');
And I bring it to the display.
{{ article }} or {{ article.body }} etc...
At this time, how do I get the city data of related to this article?
Is it'll need a complex database configuration?
The text and entity (in this case 'city' data) has no association.
Is it possible that I get the data that appears in the text or strings?
such as : SELECT c FROM MyExampleBundle:City c WHERE c.name appear in ({$text});
Although I know the example is impossible, but I wanted to know whether there is a way to easily get like a that in DQL.
In this case, I would like to get the records of 'New York' and 'Moscow'.
So you need to use the like() function with the % character. The % will act as a wildcard, for example A% will select every row where the selected field starts with A. And %A% will select every row which contains A.
public function findArticlesFromTowns($town_1, $town_2)
{
$qb = $this->createQueryBuilder('u');
$buffer = $qb
->select('a, u')
->leftJoin('a.author', 'u')
->where(
$qb->expr()->andX(
$qb->expr()->like('a.body',
$qb->expr()->literal('%'.$town_1.'%')),
$qb->expr()->like('a.body',
$qb->expr()->literal('%'.$town_2.'%'))
)
)
;
$q = $buffer->getQuery();
return $q->getResult();
}
$town_1 and $town_2 are New York and Moscow respectively. By using andX() the query will select all the rows where the body field contains New York and Moscow.
This is for Neo4j Milestone Release 2.1.0-M01. I have been trying to import this small .csv file:
Google Doc
I have tried four different formats for column D.
type: "club"
type: club
type:club
club
My Cypher query:
LOAD CSV FROM "file:<PATH_TO_FILE>/Soccer_players.csv" AS line
MERGE (p:Player {name: line[0]})
MERGE (t:Team {name: line[1]})
CREATE (p)-[:PLAYS_FOR {type: line[3]}]->(t)
When I don't include "{type: line[3]}", it imports fine. When trying to add this relationship property I get the error message
[null] is not a supported property value
Yes, I can import as a node, but why doesn't it work to set a property on a relationship in this way.
I changed the fourth column back to club/national, and also your query to get team name from the third column and didn't have any problems.
See Google Doc for a copy of your sheet updated, and my Cypher:
LOAD CSV FROM "file:filepath/Soccerplayers.csv" AS line
MERGE (p:Player {name: line[0]})
MERGE (t:Team {name: line[2]})
CREATE (p)-[:PLAYS_FOR {type: line[3]}]->(t)
neo4j-sh (?)$ match n-[r:PLAYS_FOR]->m return n.name,r.type,m.name limit 5;
+------------------------------------------------------------+
| n.name | r.type | m.name |
+------------------------------------------------------------+
| "Sergio Romero" | "club" | "Monaco" |
| "Sergio Romero" | "national" | "Argentina National Team" |
| "Mariano Andœjar" | "club" | "Catania" |
| "Mariano Andœjar" | "national" | "Argentina National Team" |
| "Agust’n Ori—n" | "club" | "Boca Juniors" |
+------------------------------------------------------------+
I had the same problem. If the CSV file has 4 columns and you are pulling data from all the 4 its gives the null property error. Hence the easy solution for me was to add a dummy 5th column in the end and load.
Maybe the importer is looking for some EOL character or something.
I want to plot a graph to see the user growth in last 30 days.
So it will an array something like this: (an incremental array)
[0,100,250,500,1000,1100.....5000,5500]
Solution 1: A stupid way to do this is to fire query for every day:
(30.days.ago.to_date..Date.today).map {|date| User.where("Date(created_at) <= ?" , date).count}
But this will fire 30 queries.
Solution 2: Find all records using group by option and then loop over it and sumup previous records.
User.group('Date(created_at)').count
(30.days.ago.to_date..Date.today).map {|date| counts[date] || 0} //and again loop over it
//and now start summing up previous ones elements to get an another array..
But both the solutions are useless. Any suggestions to make this as optimised ones.
I'll do the following :
growth = []
users = User.group('Date(created_at)').count
(30.days.ago.to_date..Date.today).each do |day|
growth.push(growth.sum + (users[day] || 0))
end
Not tested but you get the idea.
You should be able to do this with sql itself,
Ex: I have the following table
+---------+---------------------+
| user_id | training_start_date |
+---------+---------------------+
| 15981 | 2012-10-08 06:12:45 |
| 15981 | 2012-10-08 06:13:26 |
| 15981 | 2012-10-08 06:29:34 |
| 15981 | 2012-10-08 06:33:53 |
| 1005933 | 2012-10-08 07:41:54 |
+---------+---------------------+
when I want to get how many users got the training each day, I could do
select count(user_id), training_start_date from training_users group by DATE_FORMAT(training_start_date, "%M %e, %Y");
This is the link which helped me
HTH