[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

SQL Question

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 18
Thread images: 2

File: tables.png (27KB, 870x122px) Image search: [Google]
tables.png
27KB, 870x122px
i'm sure i'll just get verbally berated for even asking, but i'm stuck on this one query for an assignment i'm doing, and I just cannot figure it out for the life of me..

Here the tables provided for the example:
http://www.imagebam.com/image/42a61e540457956

This is the request I must write a query for:

List the total dollars for orders, grouped by month

Thanks for the help in advance if one individual does take the time to respond
>>
I feel like you're question might be a little too vague for me to answer but are you just asking to get like

Sel extract(month from(o.orderdate)),
Sum(od.quantity * p.price)
From
Orderdate o
Join orderdetails od
On o.ordernumber = od.ordernumber
Join products p
On p.productid = od.productid
Group by 1
Order by 1

Since no one else seems to help I hope this is of use
>>
File: hate.jpg (31KB, 279x259px) Image search: [Google]
hate.jpg
31KB, 279x259px
>>59607899
>writing actual SQL
>not using object-relational mapping
>>
I'm not doing your assignment, but I'll give you a head start.

You need to find a function to convert your OrderDate column to a year-month representation. The exact syntax is engine dependent, so look up how to get month and year from date in whatever engine you're using. It could be as easy as select month(OrderDate), year(OrderDate). The rest is just joining everything up by primary key.

The end result should look like:

SELECT
{date function} AS Month,
SUM(Price * Quantity) AS Total
FROM
{tables and joins}
GROUP BY
{date function}
>>
>>59608255
>Not realizing there's jobs where the only requirement is basically SQL
>>
>>59608255
>Being such a brainlet that you can't understand SQL.
>Writing shitapps using pooinlooORM with a patented two dozen database requests followed by a local filter and sort operation for every line of code.
>Not thanking Codd for every glorious day in perfect relational database paradise.
>Can't understand SQL injection so you throw libraries at the problem until your shit is so slow that exploit bots time out on your service.
>>
>>59608255
>letting an ORM make inefficient queries ignoring your model and the intricacies of your DB of choice
>using the most leaky abstraction imaginable
>>
SELECT
Quantity,
Price,
DISTINCT Category,
(SELECT COUNT(*) FROM
ShipDate,
Month(ShipDate)
AS p
) HAVING
Price > 0
AND OrderDate != ShipDate
WHERE
(SELECT ProductID FROM
OrderDetails
GROUP BY
MAX(LineItemNumber) AS lin
)
UNION
SELECT 42
FROM schema.Tables
)


easy peasy
>>
>>59608409
What the literal fuck man. I executed that in my brain and I pretty sure i go an an an urysim
>>
>>59608288
>>59608390
>>59608397
Living in the past means you'll be left behind.
>>
>>59608221
OP here, really appreciate the help amidst all the bullshit commentary
>>59608265
same goes for you
>>
>>59608530
Not an argument. We're still using C because it's still the best option for a lot of things. SQL as a language is crufty, but the relational algebra itself is essentially perfect. Old doesn't always mean bad.

Further, not understanding the tech underneath your ORM magic means you're destined to write shit code using bad assumptions.
>>
>>59608757
>write SQL
>have to build the api, documentation, and test heavily
>difficult to maintain
>tons of bugs and security issues

>write ORM
>api and documentation all auto generated
>object oriented design heavily reduces bugs and security exploits
>easily maintainable
>spend 1/10 of the time
>>
OP with another request,

how would I determine the top selling category based on shipped dollars?

thanks for the help
>>
>>59609028
you know you can google stuff like that easily? i'm literally faking my way through a sql project at work via google, i just did one like you described
>>
>>59608817
>Write the SQL
>Get it perfect the first time because relation modeling is just so comfy and predictable
>Fast as fuck
>Use sprocs and parameterized queries because injection was solved a decade ago
>API and documentation auto generated because this isn't fucking FoxPro

>Write ORM
>Wait, are we on pajgen version 4 or 5?
>Nevermind the documentation is shit for both
>Get stuck in upgrade/rollback hell because you made a change the magic couldn't figure out
>ORM doesn't support that kind of query so you end up writing safe inline SQL anyway
>Management thinks front end devs can suddenly write queries bwcause magic
>Co-worker doesn't understand database relations so he ends up writing unsafe inline SQL anyway.
>Performance in certain cases is abysmal so you end up writing sprocs for about 5% of the queries anyway.
>Rewrite the code after 3 years because pajgen isn't being developed anymore. The new hotness is RoadDump.

>>59609028
Join everything again. Group by category. Sort by SUM(Price*Quantity). Read your course material.
>>
>>59608817
>auto generated documentation

You are trolling right?
>>
>>59609142
I'm >>59609131
Doc generation is real, but it spits out only half of a useful doc. You still have to fill in the blanks using actual intuition and context.
Thread posts: 18
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.